Registry / serialization / lua2js

lua2js

JSON →
library0.0.11jsnpmunverified

A Lua parser and transpiler to JavaScript that generates Mozilla Parser API ASTs. The current version is 0.0.11, with no recent releases or active development evident. It targets Lua 5.1 with partial support and aims to run unmodified Lua programs in JavaScript environments. Unlike other Lua transpilers, it provides options for Lua-JS interop such as automatic conversion of LuaTable to arrays/objects and method call syntax remapping. It requires no runtime dependencies and is distributed as a single minified file. The project has significant gaps: many standard library functions (e.g., string.format, pattern matching, coroutines, debug) are missing, and certain Lua syntax features (expression table keys, goto) are unsupported. The repository appears to be in maintenance or abandoned state.

npm install lua2js
INSTALL
IMPORT
SIG · LUA2JS
L
lua2js
serializationjavascriptv0.0.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lua2js
import lua2js from 'lua2js'
const lua2js = require('lua2js')
Default import is the parser object. CommonJS require also works.
parse
import { parse } from 'lua2js'
const parse = require('lua2js').parse
Named export for the parse function.
translate
import { translate } from 'lua2js'
const lua2js = require('lua2js'); lua2js.translate(code)
Named export for the translate function.

Parses a Lua Fibonacci function and translates it to JavaScript, demonstrating basic usage of parse and translate.

import lua2js from 'lua2js'; const luaCode = ` function fib(n) if n < 2 then return n else return fib(n-1) + fib(n-2) end end print(fib(10)) `; const ast = lua2js.parse(luaCode); const jsCode = lua2js.translate(ast); console.log(jsCode); // Output: // var fib = function(n) { // if (n < 2) { // return n; // } else { // return fib(n - 1) + fib(n - 2); // } // }; // console.log(fib(10));
lua2js --version
Debug
Known issues
breakingLua standard library functions like string.format, pattern matching, coroutines, and debug are missing.
fix
Implement missing functionality or avoid using those functions in Lua code.
affects: >=0.0.0
gotchaExpression table keys (e.g., {[expr]=value}) are not supported.
fix
Use string or numeric keys only in table literals.
affects: >=0.0.0
breakingLong form strings with internal ]] may cause parse errors even with [==[ syntax.
fix
Avoid long form strings with ]] sequences; use regular strings with escaped quotes if possible.
affects: >=0.0.0
deprecatedThe project has no recent releases since 2014 and may be abandoned.
fix
Consider alternative Lua-to-JS transpilers such as lua.js, moonscript, or fengari.
affects: >=0.0.0
gotchaThe global environment _ENV and _G are not supported; globals are defined as properties of the global object.
fix
Do not rely on _ENV or _G; assign globals directly.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Lua parse error at line 1: unexpected symbol near '['
Using expression table keys which are unsupported.
fix
Replace {[expr]=value} with a string key or compute the value after table creation.
TypeError: __lua is not defined
Using luaCalls or luaOperators option without including the runtime support.
fix
Include the lua2js runtime library (dist/lua2js.runtime.js) in your project.
lua2js.parse is not a function
Importing the default export incorrectly (e.g., using require('lua2js').parse when default is the parser).
fix
Use import lua2js from 'lua2js' or require('lua2js') and then call lua2js.parse.
Upgrade
Version history
0.0.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
lua2js — npm install lua2js · libregistry