fengari-interop
fengari-interop copied to clipboard
Get keys from Lua table
I'm finding that when I convert a Lua table to JS, I can't examine its keys. Is there a way of doing this?
{ foo = 1, bar = 2}
In Javascript, I would like to type:
# ... convert above Lua to js using tojs() as object o
Object.keys(o)
Object.keys(o)
Object.keys is only able to return strings and symbols. As lua tables main contain keys of any type, this is not suitable as a default. (see #39)
However, you can use js.createProxy and a custom metamethod if you need to create an object for a specific API.
Or at least I thought you could.... I'm trying js.createproxy(setmetatable({foo=1, bar=2}, {__index=print, ownKeys=function(o) return js.global:Array("foo","bar") end})) but Object.keys on it returns an empty array (firefox 86.0)