contents   index   previous   next



WRAPPER TABLES

 

The basic idea behind a wrapper table is that it is a list of wrapper functions to be made available to your scripts. However, it has additional capabilities as well. You can define entire object classes using the table.

Here is a sample wrapper table that includes many of the options that can be used.

SELibraryTable[] my_lib = 

{  

   SE.NUMLITERAL( "Identification", “1.03”,

                  SE.DONTENUM ),

   SE.STRING( "IdentString", "Version 1.03b",

              SE.DONTENUM ),

   

   /* Move into "Clib" */

   SE.INOBJECT( "Clib",SE.DONTENUM ),

   

      /* SE.METHOD is a synonym for SE.FUNCTION */

      SE.FUNCTION( "MyFuncCall", MyFuncCallWrapper(),

                   0, 10, SE.SECURE|SE.BYREF, SE.READONLY ),

   

      SE.CLASS( "MyDate", MyDateWrapper(), 0,1,

                SE.INSECURE, SE.STOCK_ATTRIBS ),

         /* Stock attributes are DontDelete, ReadOnly,

          * and DontEnum

          */

         SE.PROTO,

            SE.FUNCTION( "valueOf", MyDateValueOfWrapper(),

                         0, 0, SE.SECURE, SE.STOCK_ATTRIBS ),

         SE.END_PROTO,

      SE.END_CLASS,

   

   SE.END_OBJECT,

   

   /* And why not some stuff in "SElib", note that 'INOBJECT'

    * is always relative to the global object

    */

   SE.INOBJECT( "SElib", SE.STOCK_ATTRIBS ),

      SE.FUNCTION( "Version", MyVersionWrapper(),

                   0,0, SE.SECURE, SE.STOCK_ATTRIBS ),

   

   SE.END_OBJECT,

   

   /* And demonstrate the last two functions. First we make

    * 'MyLib' a copy of 'Clib'. Then we change the attributes

    * on an existing variable.

    */

   SE.COPY( "MyLib", "Clib", SE.READONLY ),

   SE.ATTRIB( "varname", SE.READONLY | SE.DONTDELETE )  

}

 

As you can see, the table is a list of elements where each element is one of a number of library table methods or objects such as SE.FUNCTION or SE.CLASS. We will list each individual method or object and what it does below.

First, some overview. Most methods define something and use a name as the first parameter. For instance, the first element defines a number:

SE.NUMLITERAL( "Identification", “1.03”,

               SE.DONTENUM ),

 

When the table is added, these definitions in the table are created in the global object. Recall, members of the global object are the global variables of the script. This line therefore declares a new global variable named Identification. As the table is parsed, however, certain entries will cause this base object to change from the global object to some other object. This line is such an entry.

SE.INOBJECT( "Clib",       SE.DONTENUM ),

 

First, it too has a name Clib. It refers to the Clib member of the global object. However, the purpose of the line is to make that the new base. Therefore, new names declared after this line are no longer relative to the global object, but rather to the Clib member of the global object. A few lines later, the SE.END_OBJECT method undoes this, reverting back. This scheme allows a more readable table. It is a simple hierarchical scheme that matches well with the way objects and classes are defined.

There are two conveniences implemented. First, if you specify a name preceeded by global., for instance global.foo, the global. means that foo is relative to the global variable and the base is ignored for this entry only. Second, you can use object notation such as foo.goo. For instance, instead of writing:

SE.INOBJECT( "Clib", SE.DONTENUM ),

SE.INTEGER(  "foo", 10, SE.DONTENUM ),

 

You could instead write:

SE.INTEGER( "Clib.foo", 10, SE.DONTENUM ),

 

When using this notation, the base for further statements is not changed. The Clib. part of it applies only to this particular definition. Also, if the object referred to, in this case Clib, does not already exist or is not an object, it is converted to an object.

Choose the notation in a particular instance that is clearer. If you are going to define more than one item in an object, it is clearer to move into that object using SE.INOBJECT while a single item can be clearer to write out a dot-separated name.


WRAPPER TABLE METHODS AND OBJECT