Creating Interpreters and Contexts


Interpreters

In order to use Simkin scripting, your program must have at least once instance of the Interpreter (i.e. Interpreter in Java or skInterpreter in C++ ) class.

Some applications will work well with a single instance created at the start of the program, others may require more. You might for example want a different interpreter in each thread of your program.

For example in C++:

m_Interpreter=new skInterpreter();
in Java:
m_Interpreter=new Interpreter();
Each instance of the interpreter will have its own separate list of global variables.

ExecutableContext

In order to start executing a sequence of scripts through a Simkin interpreter, you need to create an ExecutableContext (i.e. ExecutableContext in Java or skExecutableContext in C++ ).

This object is passed to every method invoked by the interpreter, and stores information such as the interpreter being used, the current script name and the current line number.

If you are implementing a function from the Executable interface you will be passed an ExecutableContext object which you should re-use.

You should create a new ExecutableContext each time you start a call into the Interpreter, although you can use the same Interpreter object for many calls.

For example in C++:

skRValueArray args;
skRValue ret;
skExecutableContext context(m_Interpreter);
method("foo",args,ret,context);
or in Java:
Hashtable args=new Hashtable();
ExecutableContext context=new ExecutableContext(m_Interpreter);
Object ret=method("foo",args,ret,context);

Note: ExecutableContexts are also used to carry exception information where exceptions are not available (such as in Windows CE). In this case check the getError() method after calling into the interpreter.