Fobos
Fobos is a Lua 5.1 to JavaScript transpiler, written in Lua 5.1.
Fobos is not finished. Don't rely on it for another few months at best.
Notice — Fobos is not designed to port existing Lua software to JavaScript. Its main purpose is to introduce Lua as a language for web development.
Feature parity
Missing features
- Standard library
Lua 5.1 does not have a goto statementgoto
- Global variables (oddly confusing to port?)
- Use toplevel locals instead
Notes
- All Lua variables are prefixed with
l$
to avoid collisions.- For JavaScript variables to be exposed to Lua code, they must be prefixed correctly.
- Tables cannot be indexed like JS objects.
- Use the functions
index_
/newindex_
orrawget
/rawset
instead (the latter two will ignore metamethods). - JS Proxies can be used to wrap tables to make indexing more convenient.
- Use the functions
- JS objects cannot be indexed like tables
- To work around this, define helper JS functions for getting (
(obj, key) => [obj[key]]
) and setting ((obj, key, value) => [obj[key] = value]
). - As with Proxies in JS, metamethods in Lua can be used to wrap objects.
- To work around this, define helper JS functions for getting (
- JS functions must return arrays to be used via Lua
- This means functions must always return.
- To return
nil
, use[]
as a return value.
What Fobos can compile
Post-ES5 features used
- Destructuring assignment (~2016)
- let/const (~2016)
- Arrow functions (~2015)
- Map (~2014)
License
zlib.