Scripting is Fully Functional
In an earlier post, I have written that I have implemented Lua script support in the engine. Now it reached its full power since I have added a proper callback mechanism to it. It makes possible for the triggers in the engine to call user specified Lua functions on firing. Unfortunately, SWIG does not help to implement such callbacks, so I had to do it by myself.
I have declared a C++ class for callbacks that holds object (Lua table variable) and function references to be used at the calls into Lua code. The interface code is almost the same as any other class interface code generated by SWIG, the only difference is at the callback instantiation – where the code creates a new instance of Callback – it expects different types of parameters: the table and function to be called. All other mechanisms like lifecycle management and the like are the same. It is implemented using the %native directive in SWIG and some copy&paste operations from other SWIG codes… 🙂
With this, the engine now can be freely scripted even in OOP style. There is a demo showing some very basic behaviors implemented fully in Lua.
Posted on December 18, 2012, in C++, demo video, game engine, game programming, scripting and tagged C++, C++ classes, Callback, Function (mathematics), Languages, Lua, Programming, SWIG. Bookmark the permalink. Leave a comment.