contents   index   previous   next

Initialization and Contexts


Initialization is necessary before you can actually perform the tasks related to executing scripts. The first task is to initialize the engine itself. Your application only does this once when it starts and terminates the engine once when it exits. Even if you are running multiple threads in your application and running many different scripts, you only initialize the engine once. Here is a code snippet demonstrating initializing and terminating the engine:



main(int argc,char **argv)




   /* your application, including scripting. */





The other initialization task is to create an secontext. This is a handle that ties all of your scripting together. Each script you wish to run needs a context. It holds the variables, functions, preprocessor defines, and all the other information a script needs. You, as the API user, pass an secontext whenever you make a ScriptEase API call.


A single context may run more than one script one after the other but not simultaneously. If you want to run multiple scripts at once, such as in a multithreaded application, each thread will need its own context. You can create as many contexts as you like. Most applications will create a single context that is used for the life of the application then destroyed.


A newly created context will have all of the standard function libraries available for scripts in it to call. You determine which are available by your jseopt.h file as is discussed in the "Integration Into Your C/C++ Application" chapter. When the context is created, these functions are added to the global object. In JavaScript, global variables are just the members of an object, the global object. Any scripts running can see the stock libraries as global variables. This is how a script access stock objects like eval, Math, String and so forth.


To create a context, you must use the seCreateContext ScriptEase API call. The only required information for all versions is an seContextParams structure. You must fill one out and pass it as a parameter to seCreateContext. This structure is copied into the context on creation. The second parameter is a string. If you are using a trial version of the ScriptEase ISDK, you must give your userkey provided to you by Nombas. If you do not, the trial version will fail in its construction of a new context and return NULL. If you have a purchased version of ScriptEase, this second parameter is ignored.


The seContextParams Structure