[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to make a source file both valid in C and Lua?
- From: Ką Mykolas <kamicc@...>
- Date: Tue, 7 Apr 2020 10:52:27 +0300
Something like this:
On Tue, Apr 7, 2020 at 6:53 AM Xavier Wang <firstname.lastname@example.org> wrote:
> 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.
> Xavier Wang.