JSX in Lua (.luax / .tylx)¶
Recommended alternative: HTML Templates (.html)
For fullstack web applications, Orbita recommends HTML Templates (.html) with separate .tyl + .html + .css files (@if, @for, :attr, <slot />). .luax / .tylx is an optional syntax for developers who prefer inline JSX inside Lua files.
Orbita brings native JSX syntax to Lua and TypeLua through .luax and .tylx files, enabling fast Server-Side Rendering (SSR) directly inside the Luau VM.
How Transpilation Works¶
The built-in Rust transpiler transforms JSX tags into ob_jsx(...) calls before execution while preserving standard Lua comparison operators (a < b):
-- Input (.luax)
local view = <div class="hero" disabled><h1>Hello {name}</h1><br /></div>
-- Transpiled Luau output
local view = ob_jsx("div", { ["class"] = "hero", ["disabled"] = true }, { ob_jsx("h1", {}, { "Hello ", name }), ob_jsx("br", {}, {}) })
Components & Fragments¶
- Lowercase tags (
<div>,<span>,<input />) compile to HTML elements. - PascalCase tags (
<Card />,<Badge />) invoke the matching Lua function component withprops+props.children. - Fragments (
<>...</>) group multiple children without emitting a wrapper element.
-- src/page.luax
local html = require("ob:html")
local function Badge(props: { label: string })
return <span class="badge">{props.label}</span>
end
local function Layout(props: { title: string, children: any })
return (
<html>
<head><title>{props.title}</title></head>
<body>
<main>{props.children}</main>
</body>
</html>
)
end
local page = (
<Layout title="Orbita SSR">
<>
<h1>Welcome to Orbita</h1>
<Badge label="Lua + JSX" />
</>
</Layout>
)
print(html.render(page))
Direct Integration with ob:http¶
Returning a VNode directly from http.serve automatically renders it as text/html; charset=utf-8: