lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Sorry, I didn't meant to say there weren't other major differences, just not any other major differences I'm aware of that make Lua->_javascript_ translation extremely difficult. There are some Lua features that I don't think are possible using the method I've chosen for this project.

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.

Tail calls are in the _javascript_ VM's territory, for the most part. It's not great if a stack overflow is triggered in lua.js where it wouldn't be in the Lua VM, but I'm not emulating the Lua VM, so I can't control that.

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
do
  local a = 2
end
print(a)

will generate something similar to

local a_1 = 1
local a_2 = 2
print(a_1)

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 <fw@deneb.enyo.de> wrote:
* Javier Guerra Giraldez:

> 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

- tail calls

- weak references

In comparison, differences in name lookup look easier to address, and
with less of a performance impact.