lua-users home
lua-l archive

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

I did it by hand previously in a game where we didn't need to bind a lot of functions, but we needed to implement it fast (it was to script the real time cinematics in a nintendo ds game)
In my current project (in C++), I've developed my own automated binding system that uses a simple interface description language to generate a bunch of templates that allows one to enumerate and get all necessary informations for classes, their attributes and methods at compilation time with a visitor pattern (thus it is kind of a compilation time reflection system). Using those generated templates, you can write bindings for various languages or build a runtime reflection system on top of it etc.
I did this because I need to bind two things: lua, and a binary serialization system to be able to store object graphs without having to write all the loading/saving code by hand.
Both problems are kind of similar and time-consumming to implement by hand, and while you can find a lot of language binding systems around, there are not many data storage binding systems (and even if there were, using two different binding systems would complicate things a lot)
There are also further things for which some kind of reflection system come in handy.
The nice thing when you make your own stuff is that you don't need to handle anything that may exist in the wild. For instance, I don't handle raw pointers at all, the only pointers recognized by my reflection system is my own smart pointer class. This helps simplifying things a lot, but it also means that this stuff does impose constraints in the way you develop your classes.
However, this is a personal project, so I have no time or budget pressure. In a professional environment, if I had to create extensive bindings to something complete, I'd probably just use SWIG and do the data storage stuff the old fashioned way by writing load/save code manually for everything.