[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua to ECMAscript static compiler (or translator)
- From: Maximilian Herkender <static@...>
- Date: Wed, 16 Nov 2011 16:12:30 -0800
I group key values by type, to prevent any collisions (like say "2" and 2). Tables as key values is not currently supported, but they could be by assigning a unique value to each table that is created, then using that unique value as the key in their own group.
I know of no way to replicate weak tables, so that will never be supported in lua.js's current form for now.
There is a function that checks whether something is true/false, so the behavior should be the same in lua.js as in the Lua VM.
Coroutines are not yet supported, but they might be able to be recreated using web workers, otherwise it might be possible to fake them. I don't know enough about coroutines or web workers right now to say for sure.
Variable scoping was easy enough to recreate by appending the unique id of the current scope. For example...
local a = 1
local a = 2
will generate something similar to
local a_1 = 1
local a_2 = 2
That way the block-level scoping in Lua will behave the same in every experiment I've tried. I'm not completely confident the behavior of variables is the same as in the Lua VM, but I haven't found anything that suggests it is different.
On Wed, Nov 16, 2011 at 1:35 PM, Florian Weimer <firstname.lastname@example.org>
* Javier Guerra Giraldez:
- tail calls
> i see several deep differences. all doable, but only if you do real
> compilation and not just source translation.
> - Lua can use any value as a table key, JS only supports strings
> - variable hoisting vs. lexical scoping
> - 0, "" and  are falsy in JS, true in Lua
> - coroutines
- weak references
In comparison, differences in name lookup look easier to address, and
with less of a performance impact.