contents   index   previous   next



Wrapper functions

 

Wrapper functions are functions that are written in Java 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 an 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:

public void print()

{

   return new SEWrapper()

   {

      public void wrapperFunction(SEContext se, int argc)

      {

         switch( se.seGetType(SE.ARGS,SE_.NDEX(0)) )

         {

            case SE_TYPE_NUMBER:

            /* for whatever reason, need a specific number

             * format

             */

            System.out.printlm(se.seGetNumber(SE.ARGS,

                                              SE.INDEX(0)));

            break;

 

            default:

            /* Oh what the heck, just let ScriptEase convert

             * whatever it is to a String.

             */

            System.out.println(se.seGetString(SE.ARGS,

                                              SE.INDEX(0)));

            break;

         }

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

         se.sePutString(SE.RETURN,SE.VALUE,

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

      }

   };

}

 

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.


THE FUNCTION HEADER

THE ARGUMENTS

THE RETURN

WRAPPER TABLES

WRAPPER TABLE METHODS AND OBJECT

SELIBRARY INTERFACE

THE SELIBRARYMANAGER CLASS