Best way to generate a julia file full of wrapper functions

I have an API defined in an XML. On the low level it only uses a few simple functions for passing messages, and the entire XML declares higher level functions that should be wrappers around them. How should I generate a file with those wrapper functions? Should I just manually construct them via string interpolation/concatenation and output them to a file? Or maybe do a module that uses metaprogramming to generate everything on compile? Or both? Is there a way to turn expressions generated via metaprogramming back into a sane script file?

For those interested, the API is Wayland. Its C implementation uses a tool called wayland-scanner, which reads the XML and generates adequate C headers file via string concatenation.

TensorFlow.jl uses this
https://github.com/malmaud/TensorFlow.jl/blob/master/src/generate_ops.jl

To generate buld wrappers. (also to have a macro that generates even more on demand)
But I think better is to do something more like
what WordTokenizers.jl does and use @eval
to do it at compile time without serializing to file.

https://github.com/JuliaText/WordTokenizers.jl/blob/45f4aa3da4e81692c95adcef3e27a719da644296/src/words/sedbased.jl#L9-L50

1 Like