Compile to JavaScript (--target js)¶
Inspired by Gleam, Orbita includes a compiler from Lua / TypeLua (.tyl) / .luax to modern JavaScript (ES Modules) — letting you share components and logic between the Luau backend and the browser.
Usage¶
What Gets Compiled¶
- TypeLua annotations: strips type annotations (
local x: number = 1, typed parameters/returns,type Foo = { ... }declarations). - Control flow:
if / elseif / else / end,while ... do ... end, numericfor i = 1, 10 do ... end, andfor k, v in pairs/ipairs(t) do ... end. - Tables: automatically distinguishes object literals (
{ a = 1 }→{ a: 1 }) from arrays ({ 1, 2, 3 }→[1, 2, 3]). - Operators:
..→+,~=→!==,==→===,and→&&,or→||,not→!,nil→null,#x→x.length. - Top-level exports: global functions (
function Card(...)) are emitted asexport function Card(...). - Minimal runtime preamble: generated JS includes
ob_jsx,renderToString,escapeHtml, andmount(node, container)for zero-dependency browser mounting.
Example¶
Input (src/card.luax):
type CardProps = {
title: string,
}
function Card(props: CardProps)
local msg: string = "Card: " .. props.title
return <section class="card"><h2>{msg}</h2></section>
end
Output (dist/card.js):
export function Card(props) {
let msg = "Card: " + props.title;
return ob_jsx("section", { "class": "card" }, [ob_jsx("h2", {}, [msg])]);
}
Mount directly in the browser: