[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: How to make a source file both valid in C and Lua?
- From: Xavier Wang <weasley.wx@...>
- Date: Tue, 7 Apr 2020 11:53:22 +0800
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.