A complete, single-file architectural port of the Lua 5.5 source tree implemented directly in pure JavaScript.
Unlike simple regex translators, lua5.js replicates the underlying design patterns of the official Lua engine, featuring a dedicated virtual stack, mixed array/hash tables, a lexical analyzer (llex), a syntactic parser (lparser), and an instruction-driven Virtual Machine (lvm).
- Zero Dependencies: Pure vanilla JavaScript. Runs anywhere without Webpack, Vite, or Node.js.
- Double-Click Ready: Just link it inside your
index.htmland open it directly from your file manager (file://protocol). - True C-to-JS Architecture: Every single core component and library file from the official
lua.orgsource tree is represented as a structured layout module. - Isolate Engine State: Built around a custom
lua_Statetracking an isolated calculation registers stack.
The monolithic engine fully maps out the internal layout of the original C files:
| Layer | Mapped C/H Files | Description |
|---|---|---|
| Includes | lua.h, luaconf.h, lualib.h, lauxlib.h | Holds type constants, numeric limits, and library definitions. |
| Core Engine | lstate.c, lapi.c, llex.c, lparser.c, ltable.c, lvm.c | Core pipeline handles tokenization, stack management, and instruction cycles. |
| Libraries | lbaselib.c, lmathlib.c, ltablib.c, linit.c | Native execution packages exposed directly inside the global environment maps. |
| Runtime | lua.c, luac.c | Standalone operational entry layers managing execution pipelines. |
Save the monolithic framework code into a file named lua5.js.
Create an HTML file in the exact same directory:
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Lua 5.5 Virtual Machine</title><scriptsrc="lua5.js"></script></head><body><divid="terminal"><h2>Lua 5.5 VM Status: Active</h2><divid="lua-output"></div></div><scripttype="text/lua5.5">--Scopedlocaldefinitionscompiledintovirtualstackinstructionslocalalpha=150localbeta=250localresult=alpha+beta--Executionroutesthroughlbaselibprinthooksprint("Hello from the architectural Lua VM!")print("Calculated stack balance: "..result)</script></body></html>