Hacker News new | ask | show | jobs
by merlish 3387 days ago
To add some anecdotes to the above (plural of anecdote is of course data):

- fengari: Dunno, nice logo & name though :) Not done yet?

- lua.vm.js: Pretty good, but as you say in your README: "Next step is to iterate on the Lua <=> JS interoperability. Clever solutions to the lack of finalisers in Javascript are being searched for." (-> leak mem if passing stuff to JS in certain situations)

- Moonshinejs: paulcuth/gamesys' previous effort. It's a Lua VM written in JS, that accepts just Lua 5.1 bytecode. Works in IE6+. Very small. Nice 'DOMAPI' plugin; nice in the sense it mostly just works, and when it doesn't, the plugin is so small & simple you can hack it yourself.

One thing to note is when getting strings back from the DOM using DOMAPI, I've run into situations where the strings when accessed Lua-side are in fact 0-indexed not 1-indexed. (the_string .. "") is a working normalization technique.

Coroutines work very well here.

Also, do not overlook the in-browser debugger addon. It's a seriously nice piece of work, that more than makes up for the lack of source map support.

It deals with the lack of finaliers in Javascript by providing explicit .retain() and .release() mechanisms.

- Paulcuth/Starlight: As you say, transpiler, no coroutine support though.

How to get coroutines: ... I was looking into this, and you need something like using kripken's Relooper algorithm or a more general version of Facebook's Regenerator. Scary stuff.

Note about both moonshinejs & starlight, with respect to the string library: It implements Lua patterns by turning them into JS RegExp. The implementation isn't good enough as it stands; it's easy to get the wrong results, as the escaping logic is wrong. Damned if I know where though. I tried to fix it and just broke a different class of patterns...

- Brozula: Dunno

- Lua5.1.js: Dunno. Would be nice to have a better API for interaction than the Lua C API. No commits since 2013, like Brozula.

- Lua.js (lua2js): Dunno. Several open issues about e.g. '<' operator not working. No commits since 2013. And:

  _lua_coroutine["resume"] = _lua_coroutine["running"] = _lua_coroutine["status"] = _lua_coroutine["wrap"] = _lua_coroutine["yield"] = _lua_coroutine["create"] = function () { not_supported(); };
1 comments

I had a project that was doing some WebGL stuff using Lua, I found the Emscripten compiled VM to be at least 2x faster than the Moonshine. Compatibility was great, I seem to recall a lack of direct access to the underlying TypedArray. It needed something akin to a table that was directly mapped to raw memory.
That's very good to know! My current project is pretty insensitive to performance, but that's definitely useful info for the future.
It is a little extra upfront work, but I found it valuable to support a diversity of Lua VMs in Javascript because little impedance mismatches can really derail a project. Being able to switch from one to the other can isolate bugs, compare perf, memory footprint, or different interop schemes. There is literally no way to know at the beginning of a project whether any one runtime will be sufficient.