Skip to main content

Simkin Scripting Language

Simkin Tutorial

by Tim Auld <astro@tne.net.au>

This is a basic tutorial for getting Simkin setup and running with C++ (no XML here!). It involves deriving a new class that calls a function in the associated script which in turn calls a function exposed by the C++ object and retrieves, and later assigns the value of a member variable of the C++ object. I'll keep it as short as possible so you can get right to designing how your scripts will interact with your C++ objects.

First we must derive our new class from the Simkin skScriptedExecutable. This object exposes the methods required to communicate with the scripting system. The constructor takes the name of the script that will communicate with the C++ object. We must override the three standard methods in order to support that allow the script to get and set variables, and call methods in our object.

ScriptedObject.h

The implementation of the object must filter for the names of the variables and methods the object exports to the script, but still call the Simkin base class methods for others. An implementation for our ScriptedObject is:

ScriptedObject.cpp

Here you'll notice that we have implemented the private function "foo", which takes an int as a parameter. The C++ object detects that the script wants to call this function within "method". You could easily make foo return a value by inserting the return value of foo into the Simkin returnValue parameter.

Now we need to instantiate on object of our class, giving it the name of our script, which I have made "test.s". We also set up the simkin interpreter here in the main program:

test.cpp

Now comes the fun part - making a script to make our C++ program do things without having to recompile! Here I have made use of the foo function, as well as getting and setting the m_param member variable in the C++ object.

test.s

What the script is doing should be pretty self-explanitory, as I've put comments in. If you can get this up and running, you've got almost all you need. To compile the test1 project you will need to setup your directories like mine (Simkin and xerces as sibling directories of the test1 directory), or update the include and library directories to point to your location.

Please download the full sources and executable by clicking here.