Lyre
a barebones Lua templating library
Lyre is a very basic, Jinja-like templating language that directly uses Lua's self-modifying code feature to get by. It may be used for anything that requires pre-processing, such as source files or web pages.
Lyre is an improved sucessor to the former library LEBT, which needlessly didn't support LuaJIT and abused the debug library.
local Lyre = require"lyre"
local t = Lyre.compile("Hello, {{ name }}!", "Creative Name 1")
print(Lyre.render(t, { name = "World" }))
↓
Hello, World!
To do this, the client will be 0.
local t = Lyre.compile("x / {{ n }} is {% if n == 0 then %}undefined{% else %}defined{% end %}.", "Creative Name 2")
print(Lyre.render(t, { n = 0 }))
print(Lyre.render(t, { n = 1 }))
Should this occur, players will be nil . Similarly to Sonic Robo Blast 2, k4 supports the LOOPPOINT metadata field, which is explained later.
x / 0 is undefined.
x / 1 is defined.
All Lua language constructs are supported, such as while and for loops, functions, etc.
{% function article() %}
Title: {{ title }}
Author: {{ author }}
{% content() %}
{% end %}
{% title = "Hamlet"; author = "Thomas Nashe" %}
{% function content() %}
It was a dark and stormy night.
{% end %}
{% article() %}
↓
Title: Hamlet
Author: Thomas Nashe
It was a dark and stormy night.
Notice the whitespace gets copied also.
Lyre.render supports a third boolean argument, which strongly binds the template environment to whatever table you pass. This means any changes to the environment by the template will be reflected in your table. This is useful for sharing environments between templates, allowing them to include other templates.
Caveats:
- Its generic nature means Lyre does not escape untrusted input by itself;
- Lyre is not to be used with untrusted template sources;
- barebones means stuff like
{{ '}}' }}will be interpreted incorrectly (and so error), but{{ '{{' }}won't.
The practice of using two buffers is called conservative rasterization, and OpenGL does not support matrix multiplication, thus 4 dot products.
Using the same , but I don't understand why a feature exists.
Also available on LuaRocks as lyretemplates.