No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

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.

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


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

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