Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不能正常处理稀疏数组 #8

Open
wll8 opened this issue Jun 27, 2024 · 2 comments
Open

不能正常处理稀疏数组 #8

wll8 opened this issue Jun 27, 2024 · 2 comments

Comments

@wll8
Copy link
Owner

wll8 commented Jun 27, 2024

同样是中间有 null 的两个数组,为什么第一个数组出现了数据丢失?

起因

await native.unpack([1, null, 2]) // 错误
// 实例输出 [undefined, 1]
// 预期输出 [undefined, 1, null, 2]

await native.table.unpack([1, 2, null, 3]) // 正确
// 实例输出 [undefined, 1, 2, null, 3]
// 预期输出 [undefined, 1, 2, null, 3]

排查

在原生代码中 使用 thread 可以重现此问题:

import console; 
import thread.command
console.open()

var listener = thread.command.instance();
listener.publish = function(...){
  var data = {...}
  console.writeText(web.json.stringify(data), '---\r\n')
}
thread.command.publish({null, 1, 3}) // 输出 [{}] -- 数据丢失
thread.command.publish({1, null, 3}) // 输出 [[1]] -- 数据丢失
thread.command.publish({1, 2, null, 3}) // 输出 [[1,2,null,3]] -- 数据没有丢失

import win
win.loopMessage()

在原生代码中 不使用 thread 没有重现此问题:

import console

fn = function(...){
  var data = {...}
  return table.unpack(data); 
}

console.dumpJson(fn({1, null, 3})) // 输出 [1, null, 3]

import web.json
console.writeText(web.json.stringify({1, null, 3}), '---\r\n') // 输出 [1, null, 3]

import win
win.loopMessage()

环境

  • sys-shim v0.0.1-15
  • aardio v36.19.1
@wll8
Copy link
Owner Author

wll8 commented Jun 27, 2024

aardio 作者回复:

image

aardio 文档:

image

数组含 null 实例输出:

代码:

import console
var array = { "值:1", null, "值:2", "值:4" } 

console.dump(array)
import win
win.loopMessage()

输出:

{
[1]="值:1";
[3]="值:2";
[4]="值:4"
}table: 029F4860

@wll8
Copy link
Owner Author

wll8 commented Jun 28, 2024

Deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant