Skip to content

thenumbernine/lua-template

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

Donate via Stripe
Donate via Bitcoin

This is the template function that was in my LuaJIT-driven HydroCL project. I liked it so much I put it in its own project, so other projects could use it.

Here's an example of how it works. Similar to PHP.

The 's wrap executed code and the wrap automatically printed code.

Dependencies:

Example:

local template = require 'template'
fields = {
	{a = 'int'},
	{b = 'const char*'},
	{c = 'double'},
}
print(template([[
typedef struct {
<? for _,name_ctype in ipairs(fields) do
	local name, ctype = next(name_ctype)
?>	<?=ctype?> <?=name?>;
<? end
?>} S;
]], {
	fields = fields,
}))

...produces...

typedef struct {
	int a;
	const char* b;
	double c;
} S;

...which fits perfectly inside a ffi.cdef() call.

About

Lua Templates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages