To build these files yourself, use make in the root of the project, for example...
(the CLOSURE_COMPILER variable only needs to be set if you're building the minified versions of the scripts)
./lua2js input.lua output.js
(node is required to run lua2js)
When a script generated by lua2js is run, the variable
lua_script will be set to the global variable (_G) of the script. You can use this variable to interact with the script using the functions in lua.js/lua.as.
If you are dealing with multiple Lua scripts, modules should be used. They can be used normally for inter-Lua interactions, and the
lua2js also generates valid ActionScript code as well. Include lua.as (not lua.js) and the generated file to make it work.
You can also use the function
lua_load() to parse Lua code in the browser.
lua_load() is only available when the lua+parser.js version of lua.js is used.
lua_load() will parse the script, and return a function that will execute the script when called and returning the global variable of that script.
- There are missing library functions and incomplete implementations of some functions. They should all be marked with TODO comments, or throw "Not supported" errors.
- The global table does not currently support metatables.
- Some Lua functions do not handle error conditions in the same way as standard Lua does.
- Nested comments (e.g.
--[=[ ]=]--) are not supported
__gcmetamethods are not supported
Some implementation details
- This project works by converting Lua code directly to ECMAscript. An alternative solution would be to emulate a Lua VM to better maintain compatibility, but this would be much slower.
- Lua functions in ECMAscript always return arrays. This is to support the multiple return values that Lua uses.
- Tables are normal objects with sub-objects (str, uints, etc) that seperate different kinds of keys from each other.
uintskey in an object can be an array or an object, depending on how it is used. If
table.insertis used for example, then it will be converted to an array if it is not already one. To force uints to be one thing or another, use
ensure_notarraymode()to require it be available in a certain form.
- lua.js can be compiled using Closure Compiler's ADVANCED_OPTIMIZATIONS mode for a dramatically smaller total file size. This is more complicated than traditional minifying so you'll need to use variable maps or combine Lua-related scripts together.