Open Egor-Skriptunoff opened 5 years ago
See https://github.com/fengari-lua/fengari-interop#createproxyx-type Especially see the note:
Note that JavaScript coerces all types except Symbols to strings before using them as a key in an indexing operation.
In JS, if you do mything[1]
, then it converts it to a string before doing the index operation. Meaning that you see mything["1"]
. This goes for all objects (not just numbers): if you do mything[{}]
then you get mything["[object Object]"]
.
This really gets in the way of trying to use lua tables as JS objects.
Instead, the default conversion of lua objects to JS is more like a JS Map
object, with .get
, .set
, .has
methods etc.
please add a function
js.dict(lua_table)
which will convert Lua-curly-braces into JS-curly-braces. This function would make creating a JS dictionary on Lua side a lot easier:window:Split(window:Array('#Left', '#Right'), js.dict{gutterSize = 15, minSize = 270, sizes = window:Array(25, 75), snapOffset = 0, expandToMin = true})
Yes, I know that I can write such function myself on Lua side, but this function is a "must-have" for every developer.
I use such a function myself (https://gist.github.com/daurnimator/5a7fa933e96e14333962093322e0ff95/) e.g. here
So far fengari-interop doesn't have any "helpers"; so this would be quite a new concept for the library. Though you're probably right that it would be useful...
Is the default conversion of objects to JS is a WeakMap
?
Is the default conversion of objects to JS is a
WeakMap
?
no, the default is an object with methods .get
, .set
etc, similar to a Map
.
I want to translate this JS one-liner to Lua:
This works, but is too bulky:
This looks nice, but doesn't work:
Why Fengari doesn't convert Lua tables to JS dictionaries on-the-fly? It's too boring to write this conversion manually.
If there are some reasons why such conversion could not be done automatically, please add a function
js.dict(lua_table)
which will convert Lua-curly-braces into JS-curly-braces. This function would make creating a JS dictionary on Lua side a lot easier:Yes, I know that I can write such function myself on Lua side, but this function is a "must-have" for every developer.