contents   index   previous   next

Wrapper functions


Wrapper functions are script functions that are written in C using the ScriptEase API instead of being written in JavaScript. From the script's point of view, they appear just like any other function and can be called identically. Most wrapper functions are initialized by the application before running scripts so as to be available to the script user right from the start. This is done by writing a wrapper function table and adding it to your secontext using the seAddLibTable ScriptEase API call. The table is added before the application makes any calls to the seEval ScriptEase API call. All of the standard ECMAScript objects, such as String, Math, or Number, are written using wrapper functions and wrapper function tables, so you have a large body of example wrapper functions included with ScriptEase to look at.


Here is a sample wrapper function, to get an idea of how one looks. The rest of this chapter is devoted to demystifying it:


   SE_CALLBACK( void )

print(secontext se,sememcount argc)


   switch( seGetType(se,SE_ARGS,SE_INDEX(0)) )


      case SE_TYPE_NUMBER:

         /* for whatever reason, need a specific number

          * format






         /* Oh what the heck, just let ScriptEase convert

          * whatever it is to a String.





   /* let's return something because we can */


                  "Go away, you bother me kid.",SE_PS_STRLEN);



Before looking into the wrapper function tables, a basic overview of a wrapper function is necessary. The example above is simple but it demonstrates all that a wrapper function does. It gets its arguments, uses them to perform the body of the wrapper function, and returns a result.