lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

I'm seeking a solution that uses Lua as the preprocessor of pure C.
For now, I make a Lua script to generate C code.

Just for a brainstorming: Is there a way to construct a single source
file, that's both a valid Lua script
(to generate C source from itself as a template) and also a valid C
source (header) which could just include into other
C source as-is?

currently, I could find a way that uses -- BEGIN and -- END surround
the Lua code, and comment it into C comment, just like this:

/*
-- BEGIN
-- this is Lua code ...
-- END */
this is C code

and use sed -n '/BEGIN/,/END/p' | lua to run.

Just for curiosity, Is there a way makes me run these code just like:

lua template.c # re-generate template.c file itself.
gcc -o template template.c # use it as C code and compiles.

-- 
regards,
Xavier Wang.