XML syntax for Lua - write XML directly in your Lua code, similar to JSX in JavaScript.
🌐 Language / Idioma / Idioma: English | Português | Español
luarocks install daviluaxml-- Register the loader for .lx files
require("DaviLuaXML")
-- Now you can use require() with .lx files
local App = require("my_component")-- component.lx
local function Button(props, children)
return string.format('<button class="%s">%s</button>',
props.class,
children[1]
)
end
local function App()
return <div class="container">
<h1>Hello World!</h1>
<Button class="primary">Click here</Button>
</div>
end
return AppDaviLuaXML transforms XML tags into Lua function calls:
-- This:
local el = <div class="container">Hello</div>
-- Becomes:
local el = div({class = "container"}, {"Hello"})The function receives two arguments:
props- table with the attributeschildren- table with the children (text, numbers or other elements)
<div/> -- Self-closing tag
<p>text</p> -- Tag with content<btn class="primary"/> -- String
<input value={variable}/> -- Lua expression
<comp enabled/> -- Boolean (true)<sum>{1}{2}{3}</sum> -- Multiple values
<p>{name .. " " .. surname}</p> -- Lua expressions<div>
<span>text</span>
<ul>
<li>item 1</li>
<li>item 2</li>
</ul>
</div><html.div class="x"/> -- Becomes: html.div({class = "x"}, {})Registers the loader for .lx files. After that, require() works with .lx files.
local lx = require("DaviLuaXML.core")
local result, err = lx("file.lx")Directly executes an .lx file by path.
local help = require("DaviLuaXML.help")
help() -- General help
help("syntax") -- Specific topic
help.list() -- List topics
help.lang("en") -- Set language (en, pt, es)DaviLuaXML uses loglua for logging. Debug logs are in the XMLRuntime section:
require("DaviLuaXML")
require("my_module")
-- Show runtime debug logs
log.show("XMLRuntime")| Module | Description |
|---|---|
init |
Registers the searcher for require() |
core |
Directly executes .lx files |
parser |
Parses XML tags |
transform |
Transforms XML to Lua |
elements |
Creates elements (tables) |
props |
Processes attributes |
errors |
Error formatting |
help |
Help system |
lua DaviLuaXML/test/run_all.lua- Lua >= 5.4
- loglua
MIT