First, you need to create an instance of the skInterpreter class. This
is usually done at the beginning of your application:
void main() { // Set up global interpreter skInterpreter interpreter; // set up an executable context skExecutableContext ctxt(&interpreter); // application code .... // e.g. call an entry point skRValueArray args; skRValue return_value; obj.method("init",args,return_value,ctxt); }
To expose fields and methods in your C++ classes you derive from
the Simkin base classes skiExecutable or skExecutable.
skiExecutable is an abstract base class for maximum flexibility. skExecutable provides a better starting point, as it implements all the abstract methods.
For example (click on the highlighted method to see its implementation):
class Person : public skExecutable { public: bool getValue (const skString& fieldName, const skString& attribute, skRValue& value); // returns a field's value bool setValue (const skString& fieldName, const skString& attribute, const skRValue& value); // sets a field's value bool method (const skString& methodName, skRValueArray& arguments,skRValue& returnValue); // calls a method in this object private: skString m_Name; skString m_EmailAddress; };You can also derive from skElementExecutable, skXMLExecutable or skScriptedExecutable. These classes load a Simkin script from files.
Their versions of "getValue", "setValue" and "method" find their values and behaviour from the Simkin script file. You can override these to add your own specialized C++ behaviour.
For example (click on the highlighted method to see its implementation):
class ScriptablePerson : public skXMLExecutable { public: bool getValue (const skString& fieldName, const skString& attribute,skRValue&; value); // returns a field's value bool setValue (const skString& fieldName, const skString& attribute,const skRValue& value); // sets a field's value bool method (const skString& methodName, skRValueArray& arguments,skRValue& returnValue); // calls a method in this object private: skString m_Name; skString m_EmailAddress; };Please see Example.cpp which shows all of this.