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.

Advertisements

Posted on December 18, 2012, in C++, demo video, game engine, game programming, scripting and tagged , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: