[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: Polyglot Lua+C
From:       Hugo Musso Gualandi <hgualandi () inf ! puc-rio ! br>
Date:       2022-05-20 20:40:49
Message-ID: F64EB52B-5DEB-4219-B7CE-EA7D501CB91F () inf ! puc-rio ! br
[Download RAW message or body]

The long story is that I have a compiler, written in Lua, that generates C =
as output=2E
Previously what we did was that the generated C code would #include that h=
eader file=2E 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 generat=
ed C code=2E

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

The first version needed to  simultaneously act as a Lua string and as som=
ething you could #include, hence the hack=2E Later, I found a way to no lon=
ger need this dual purpose so now it is just a Lua string without the hack=
=2E But it's still a cool trick so I wanted to share it :)
[Attachment #3 (text/html)]

<!DOCTYPE html><html><body>The long story is that I have a compiler, written in Lua, \
that generates C as output.<br>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.<br><br>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 <a href="https://github.com/hishamhm/datafile">https://github.com/hishamhm/datafile</a> \
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.<br><br>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 :)</body></html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic