lua-users home
lua-l archive

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


The long story is that I have a compiler, written in Lua, that generates C as output.
Previously what we did was that the generated C code would #include that header file. But it was awkward because the header gets installed in a non standard location and we must pass the right -I flags to build the generated C code.

The current design is to include the contents of the header file verbatim into the generated C code. That way there is no #include and no worry about compiler flags. The saner way to do this would be to package the header as a data file and use https://github.com/hishamhm/datafile to copy it. But I didn't want to add another dependency. Instead, we put the header file string inside a Lua module, which is something that vanilla Luarocks knows how to work with.

The first version needed to simultaneously act as a Lua string and as something you could #include, hence the hack. Later, I found a way to no longer need this dual purpose so now it is just a Lua string without the hack. But it's still a cool trick so I wanted to share it :)