terralang / terra

Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.
terralang.org
Other
2.71k stars 197 forks source link

Exporting C header file from Terra types #374

Open aiverson opened 5 years ago

aiverson commented 5 years ago

Is there a function to write out a C header file that can be #included in a C program so that a library written in terra can be linked to from c without needing to manually write a c header file?

Or do I need to write it myself?

capr commented 5 years ago

There's one here https://github.com/luapower/terra-low (the function is called publish) and is used here https://github.com/luapower/terra-layer (look at the very end of the layer.t, the generated header is layerlib_h). It not only generates C-defs but also ffi.metatype declarations so you can consume the library from LuaJIT directly with methods. You could strip that part out and only keep the cdefs (actually that function also does the building and linking, strip that out too).