Creating a LUA plugin
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, Mildred!
Setup your enviroment
The very first step is download, complie 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 director, . 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.)
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:
#include <ivaria/script.h> #include <iutil/eventh.h> #include <iutil/comp.h> #include <csutil/csinput.h> #include <iutil/string.h>
Then we introduce a new namespace to avoid name conflicts, in Crystal Space way:
This macro creates for us a new cslua namespace.
Now we can to start