The --lua build target transpiles Oak programs to Lua 5.4. This enables embedding Magnolia logic in Lua-hosted environments like game engines, Redis, Nginx/OpenResty, and Neovim.
oak build --entry main.oak --output bundle.lua --luaThe output is a self-contained Lua 5.4 script that includes:
- Runtime preamble: Oak compatibility functions (
__oak_eq,__oak_push,__oak_acc, etc.) - Module system:
__oak_modularize/__oak_module_importregistry - Transpiled code: All module code converted to Lua syntax
| Oak Feature | Lua Equivalent |
|---|---|
| Functions | function(...) end |
| Closures | Lua closures (upvalues are mutable by default) |
| Objects | Lua tables with string keys |
| Lists | Lua tables (note: 0-indexed in Oak, 1-indexed in Lua) |
| Atoms | String constants |
| Pattern matching | if/elseif/else chains |
Pipe |> |
Nested function calls |
null |
nil |
true/false |
true/false |
__oak_eq(a, b)— Deep structural equality comparison__oak_push(tbl, val)— Append to table__oak_acc(obj, key)— Safe property access__as_oak_string(v)— String coercion for+operator__oak_and(a, b)/__oak_or(a, b)— Short-circuit logical operators__oak_xor(a, b)— XOR for booleans and integers
Lua reserved words are prefixed with __oak_lua_:
and, break, do, else, elseif, end, false, for, function,
goto, if, in, local, nil, not, or, repeat, return, then,
true, until, while
- Strings: Lua strings are immutable. Oak's mutable string indexing is not fully supported.
- Array indexing: Lua arrays are 1-indexed. External Lua code interfacing with Oak lists should account for this.
- Async: Oak's
go(), channels, andwait()are not supported in the Lua target. - Operator polymorphism: Bitwise operations on strings are not supported.
- Game engines (LÖVE, Defold, Corona)
- Redis stored procedures
- Nginx/OpenResty scripting
- Neovim plugin development
- IoT/embedded scripting environments