lua
Luau syntax highlighter. Pure `(text) -> { Segment }`. Mirrors the algorithm of the deleted Rust `highlight_lua` / `highlight_lua_code_part` pair (renderer.rs pre-Phase-3): `--`-line comments, single- and double-quoted strings (no escape handling), digit runs with optional dots (…
lua
Luau syntax highlighter. Pure (text) -> { Segment }. Mirrors the
algorithm of the deleted Rust highlight_lua / highlight_lua_code_part
pair (renderer.rs pre-Phase-3): ---line comments, single- and
double-quoted strings (no escape handling), digit runs with optional
dots (no exponent), and identifiers dispatched against the Luau keyword
set. Colors flow from ui.getToken("code.<role>") via the active theme,
with hardcoded fallbacks matching the deleted Rust constants.
Exports
highlight(text: string) -> { Segment }— tokenize a Luau string into colored segments for the zui code renderer. The module returns this function directly.
Types:
Segment = { text: string, color: string, monospace: boolean }
Usage
local highlight = require("@builtin::modules.zui.highlight.lua")
local segments = highlight("local x = 1 -- pi-ish")
Notes
- Pure function — no side effects, no state. Safe to call any time.
- The
ui.getTokenlookup runs once per highlighter call (5 FFI calls), then locals are used in the hot tokenize loop — cost is per-call, not per-byte. - Strings have no escape handling (
"a\"b"would terminate at the middle quote). This matches the deleted Rust implementation exactly.
Scoped to this part · feeds back into the world's score.