r/lua • u/RGBhedy • Jun 09 '26
Library templa: a Lua 5.4 native template engine (drop-in replacement for etlua)
etlua is the standard Lua template engine but it relies on setfenv which doesn't exist in 5.4. Its shim uses debug.upvaluejoin which breaks in sandboxed environments.
templa is a drop-in replacement built for stock Lua 5.4:
- same <%= %>, <%- %>, <% %> syntax
- no debug library required, safe in sandboxes
- coroutine-safe
- 34% faster compiled rendering, 5x lower GC pressure than etlua
luarocks install templa
19
Upvotes
1
u/yawara25 Jun 09 '26
Nice work, thank you for sharing. I like to see the web applications of Lua getting some attention.
1
u/no_brains101 Jun 10 '26
its 4-5 files, none of which are very long, why bundle it? Could just be 1 400 line file, no? Or just left as a dir? The rtp search only happens on the first require. Looks nice though! Next time I feel like trying to do this kind of thing in lua I will give it a try.