daurnimator / lua.vm.js

The project is superceded by Fengari. See https://fengari.io/
MIT License
836 stars 101 forks source link

0.0.1 crashes when trying to [i]pairs a js array #51

Closed jaredallard closed 8 years ago

jaredallard commented 8 years ago

Hi. Pretty simple reproduction. Using 0.0.1 via npm, will try master soon.

nodejs only

var array = [ 'item', 'item2', 'item3'];
local arr = myFuncToGetJSArray();
for i, v in ipairs(arr) do
   print(v)
end

Pure Lua:

local tble      = {}
tble[1]         = 'item';
tble[2]         = 'item2';
local arr = js.global:Array(table.unpack(tble))
for i, v in ipairs(arr) do
   print(v)
end

EDIT: self built from master fails as well.

jaredallard commented 8 years ago

31 is why this doesn't work. Inject the line below this.gc at commit fa9d5921c60e9c640988f17f34841269f89ea16d and this is fixed.

daurnimator commented 8 years ago

Huh? So is it fixed in master or not?

Your sample works in the repl at https://kripken.github.io/lua.vm.js/repl.html for me.

jaredallard commented 8 years ago

@daurnimator Sorry for being confusing, this is in a node.js env.

daurnimator commented 8 years ago

@daurnimator Sorry for being confusing, this is in a node.js env.

Works for me:

$ node 
> require("./dist/lua.vm.js").L.execute('for i,v in ipairs(js.global:Array(table.unpack({"item", "item2"}))) do print(v) end')
item
item2
[]
>
daurnimator commented 8 years ago

@jaredallard did you figure this out?

jaredallard commented 8 years ago

@daurnimator Hey, for me this didn't work. The only way I got it to work was doing the aforementioned fix beforehand. Though I haven't used this in a awhile, so it is possible something may have been changed to fix it.

daurnimator commented 8 years ago

Closing as it works for me. Will reopen if you can reproduce.