contents   index   previous   next



WRAPPER MACROS

 

What follows is a description of each macro you can use in a wrapper table and what each does.

 

syntax:

SE_BEGIN_LIB_TABLE(name)

description:

All wrapper tables are started with this macro. It specifies the name of the table. Use the table name in your call to seAddLibTable to add the wrapper table to your context.

 

 

syntax:

SE_INITFUNC(func)

description:

Specify a function to be called whenever the table is initialized. The function's type must be:

 

typedef SE_CALLBACK(void *) (*seLibraryInitFunc)(secontext se,void *userdata);

 

 

The initial data you pass in to seAddLibTable (as its final parameter) is passed to the initialization function. That initialization function in turn returns the userdata for the particular instance of the library table. It could just return the userdata to use the same data for all instances. If there is no initialization function, the supplied data is used directly in all instances of the library.

 

Note that the library can be initialized more than once, and you must be prepared to handle that case. The first time the library is initialized is when you call seAddLibTable, but the library will be reinitialized in certain circumstances.

 

 

syntax:

SE_TERMFUNC(func)

description:

The companion to the initialization function, the term function looks like:

 

typedef SE_CALLBACK(void)

*seLibraryTermFunc)(secontext se,void *userdata);

 

 

When the library terminates, it passes its instance (not the original instance) of the userdata, the value returned from the initialization function. For each call to the initialization function, there will be one call to the termination function.

 

 

syntax:

SE_NUMLITERAL(name,string,vflags)

description:

Create a variable in the current base object with the given name and the given value. The string passed must be parsable as a floating point number. The flags of the variable are set to the vflags value. The allowable flags are:

 

SE_DEFAULT No special attributes

 

SE_READONLY The member is read-only and cannot be modified.

 

SE_DONTENUM The member should not be enumerated when a script uses for..in.

 

SE_DONTDELETE The member cannot be deleted using the JavaScript delete operator.

 

 

syntax:

SE_INTEGER(name,number,vflags)

description:

Create a variable in the current base object with the given name and the given value. Identical to SE_NUMLITERAL, except an integer value is given.

 

 

syntax:

SE_STRING(name,string,vflags)

description:

Very similar to SE_NUMLITERAL, except the variable is set to a string value.

 

 

syntax:

SE_INOBJECT(name,vflags)

description:

The given name is treated as an object, and if the name is not currently an object, it is turned into one. The object has its flags set to the vflags value. Finally, that object is the new base for all names until an SE_END_OBJECT is found.

 

 

syntax:

SE_END_OBJECT

description:

Undoes the SE_INOBJECT above so all names are derived from the base before the SE_INOBJECT took effect.

 

 

syntax:

SE_FUNCTION(name,func,min_args,max_args,

            func_flags,var_flags)

description:

Declares a wrapper function. The parameters are the function's name, the function itself (a wrapper function), the minimum and maximum number of arguments, the function flags, and the variable flags.

 

The maximum number of arguments can be -1 to specify no limit.

 

The function flags are one or more from the following:

 

SE_DEFAULT No special flags.

 

SE_DYNAUNDEF The object's dynamic callbacks are only called if the object does not already have the member in its internal storage, or if that member is SE_TYPE_UNDEFINED. (See "DYNAMIC OBJECTS" for a complete description of callbacks.)

 

SE_BYREF Parameters passed to this function are passed by reference, so that any changes to them are reflected in the variables passed as the parameters.

 

SE_SECURE The function is secure. Only mark a wrapper function as secure if it can not perform any dangerous task. When in doubt, do not make it secure. The general rule is that any access to the system, such as reading a file or calling a system function, makes a function insecure.

 

SE_KEEP_GLOBAL Normally when a function is executed, the global object in effect when the function was created is used as the global object when the function is executed. With this flag, the current global object is retained whenever the function is executed.

 

 

syntax:

SE_METHOD(name,func,min_args,max_args,

          func_flags,var_flags)

description:

This is a synonym for SE_FUNCTION.

 

 

syntax:

SE_CLASS(name,func,min_args,max_args,

         func_flags,var_flags)

description:

This works similarly to SE_FUNCTION in that it adds the given entry as a function. However, as a class, such a function is expected to be used as a constructor. Several additional items are therefore created to facilitate this. First, the function is given a prototype which has the attributes SE_STOCK_ATTRIBS. Second, the prototype is given an _class member with a name equal to the name of the class. Finally, the prototype also gets a constructor member which points back to the class. All of these items are standard for ECMA classes.

 

After this table entry is finished, the base is moved to the class object so you can add members or use SE_PROTO to add prototype members. This works in the same way SE_INOBJECT works. Use SE_END_CLASS to move back out of the object.

 

 

syntax:

SE_END_CLASS

description:

Changes the base to its value before the SE_CLASS entry.

 

 

syntax:

SE_PROTO

description:

Changes the base to the prototype of the current object. This is used to define the methods available to members of the current class. It is identical to:

 

SE_INOBJECT(UNISTR(“prototype”)).

 

 

syntax:

SE_END_PROTO

description:

Changes the base to its value before the SE_PROTO entry.

 

 

syntax:

SE_COPY(name,source,var_flags)

description:

Acts as an assignment, copying the source value to the given name. It sets the destination flags as well.

 

 

syntax:

SE_ATTRIB(name,var_flags)

description:

Sets the variable flags on a given name, changing nothing else about it.

 

 

syntax:

SE_END_LIB_TABLE

description:

This must be the last entry in a wrapper table.