Lua for LiaScript: Execute Lua Scripts Interactively in the Browser
- André Dietrich
- Template , Tutorial
- May 28, 2026
Lua is lightweight, fast, embeddable, and widely used — in game development (Roblox, World of Warcraft, Löve2D), embedded systems, configuration scripting, and teaching. Its simple syntax and minimal runtime make it an excellent first language.
The Lua template brings a complete Lua virtual machine to LiaScript, based on an Emscripten port of the reference Lua interpreter. Code runs entirely in the browser, no server needed.
Quick Start
<!--
import: https://raw.githubusercontent.com/liaTemplates/Lua/master/README.md
-->
One macro: @Lua.eval.
@Lua.eval — Execute Lua Code
Attach @Lua.eval to any Lua code block.
The block becomes editable and executable; output from print() appears in the console.
```lua
print("Hello from Lua!")
for i = 1, 5 do
print(i .. "^2 = " .. i*i)
end
```
@Lua.eval
JavaScript Interoperability
The Lua VM runs inside the browser JavaScript environment, which means Lua code has direct access to browser globals via the js library.
This is a unique feature that enables cross-language experiments.
```lua
-- Access the browser window object
local window = js.global
-- Alert dialog
window:alert("Hello from Lua!")
-- Screen information
local screen = js.global.screen
print("Screen: " .. screen.width .. "x" .. screen.height)
-- Current time
print("Time: " .. js.global.Date.now())
-- Run JavaScript from Lua
local result = js.global:eval("[1,2,3,4,5][2]")
print("JS array index 2: " .. tostring(result))
```
@Lua.eval
This is especially useful in courses that compare languages: students can see how the same operation works in both Lua and JavaScript.
Full Template Demo
Use Cases
Introductory scripting — Lua’s syntax is minimal and readable. Variables, functions, loops, and tables are enough to teach core programming concepts without syntactic overhead.
Game development courses — Lua is the scripting language for Roblox and many game engines. Introduce game logic concepts — state machines, event handlers, entity systems — with real Lua syntax.
Embedded systems and scripting — Lua is widely used as an embedded scripting engine (OpenWrt, Redis scripting, Nginx/OpenResty). Teach configuration scripting in a relevant language.
Cross-language comparison — The JavaScript interop (js.global) makes it practical to show the same operation in both Lua and JavaScript side by side in a LiaScript course.
Technical Facts
| Runs in browser | Yes — Emscripten Lua VM |
| Server required | No |
| Lua version | 5.x (via emscripten port) |
| JS interop | Yes — js.global and js.new() |
| Console output | Yes — print() maps to console.log |
| License | MIT (implied) |
| Maintained | Stable (version 0.0.1) |
Try It
Try in LiaScript Open in LiveEditor View on GitHubRelated Templates
- Pyodide — full Python via WebAssembly, also runs in the browser
- BiwaScheme — Scheme/Lisp interpreter in the browser
- JSCPP — C++ interpreter in the browser
- WebDev — HTML, CSS, and JavaScript with live preview