Toolbox

Contents

Creating a LUA plugin

Short indtroduction

In this tutorial we will create a plugin for integrating Lua. That means, you can reach the the whole CS API with LUA scripting. Note, you can any SWIG supported language integrate easily into Crystal Space. In that case, when SWIG is new for you, please have a look at the project here:

A note about the history of this plugin.
The source itself is just partially my work. The original code written by Brandon Ehle in 1999. I started to update the code, but the greater part of the code written by Mildred. Many thanks for her efforts.

Setup your enviroment

The very first step is download, compile and install LUA. You can get it from the official site:

You can find here also some precompiled version, you can use them, when you want.
This tutorial uses the LUA 5.1 version.

The next step is setting up an external CS project within your enviroment. Don't forget to set up your project as a dynamic link library, and the neccessary CS and LUA libs and include directories . The concrete steps depending from your IDE and operating system. ( This is a so called professional tutorial. Professional tutorials are not just for C++ masters , but I assume, you can set up this project without any external help.)

Start coding

Crystal Space uses the iScript interface to communicate with scripting languages, so we have to implement this interface to integrate LUA. So we include some CS headers:

First we define the constructor and the virtual destructor. The shared_instance is a static csLua instance, this object will be used by Crystal Space. We need a know about the ObjectRegistry, object_reg will store a pointer to this. The lua_State* is a special statment indicator, when you knows Lua, yo know, what is it.