Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

lua5.js 🌙

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).


🚀 Key Features

  • Zero Dependencies: Pure vanilla JavaScript. Runs anywhere without Webpack, Vite, or Node.js.
  • Double-Click Ready: Just link it inside your index.html and 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.org source tree is represented as a structured layout module.
  • Isolate Engine State: Built around a custom lua_State tracking an isolated calculation registers stack.

📂 Lua 5.5 Source Tree Mapping

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.

📦 Installation & Usage

1. Create lua5.js

Save the monolithic framework code into a file named lua5.js.

2. Setup your index.html

Create an HTML file in the exact same directory:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Lua 5.5 Virtual Machine</title>
    <script src="lua5.js"></script>
</head>
<body>

    <div id="terminal">
        <h2>Lua 5.5 VM Status: Active</h2>
        <div id="lua-output"></div>
    </div>

    <script type="text/lua5.5">
        -- Scoped local definitions compiled into virtual stack instructions
        local alpha = 150
        local beta = 250
        local result = alpha + beta
        
        -- Execution routes through lbaselib print hooks
        print("Hello from the architectural Lua VM!")
        print("Calculated stack balance: " .. result)
    </script>

</body>
</html>

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages