SwfdecAsFunction

SwfdecAsFunction — script objects that can be executed

Synopsis




                    SwfdecAsFunction;
void                (*SwfdecAsNative)                   (SwfdecAsContext *context,
                                                         SwfdecAsObject *thisp,
                                                         guint argc,
                                                         SwfdecAsValue *argv,
                                                         SwfdecAsValue *retval);
                    SwfdecAsNativeFunction;
SwfdecAsFunction*   swfdec_as_function_create           (SwfdecAsContext *context,
                                                         GType type,
                                                         guint size);
void                swfdec_as_function_call             (SwfdecAsFunction *function,
                                                         SwfdecAsObject *thisp,
                                                         guint n_args,
                                                         const SwfdecAsValue *args,
                                                         SwfdecAsValue *return_value);
SwfdecAsFunction*   swfdec_as_native_function_new       (SwfdecAsContext *context,
                                                         const char *name,
                                                         SwfdecAsNative native,
                                                         guint min_args);
void                swfdec_as_native_function_set_construct_type
                                                        (SwfdecAsNativeFunction *function,
                                                         GType type);
void                swfdec_as_native_function_set_object_type
                                                        (SwfdecAsNativeFunction *function,
                                                         GType type);

Description

Functions is the basic object for executing code in the Swfdec script engine. There is multiple different variants of functions, such as script-created ones and native functions.

If you want to create your own functions, you should create native functions. The easiest way to do this is with swfdec_as_object_add_function() or swfdec_as_native_function_new().

In Actionscript, every function can be used as a constructor. If you want to make a native function be used as a constructor for your own SwfdecAsObject subclass, have a look at swfdec_as_native_function_set_construct_type().

Details

SwfdecAsFunction

typedef struct {
} SwfdecAsFunction;

This is the base executable object in Swfdec. It is an abstract object. If you want to create functions yourself, use SwfdecAsNativeFunction.


SwfdecAsNative ()

void                (*SwfdecAsNative)                   (SwfdecAsContext *context,
                                                         SwfdecAsObject *thisp,
                                                         guint argc,
                                                         SwfdecAsValue *argv,
                                                         SwfdecAsValue *retval);

This is the prototype for all native functions.

context : SwfdecAsContext
thisp : the this object.

Warning

Can be NULL.
argc : number of arguments passed to this function
argv : the argc arguments passed to this function
retval : set to the return value. Initialized to undefined by default

SwfdecAsNativeFunction

typedef struct {
} SwfdecAsNativeFunction;

This is the object type for native functions.


swfdec_as_function_create ()

SwfdecAsFunction*   swfdec_as_function_create           (SwfdecAsContext *context,
                                                         GType type,
                                                         guint size);

Creates a new function. The function will be of type. It will be added to context and its prototype and constructor object will be set correctly.

context : a SwfdecAsFunction
type : the type of function to create
size : size of type
Returns : a new object of type or NULL on OOM

swfdec_as_function_call ()

void                swfdec_as_function_call             (SwfdecAsFunction *function,
                                                         SwfdecAsObject *thisp,
                                                         guint n_args,
                                                         const SwfdecAsValue *args,
                                                         SwfdecAsValue *return_value);

Calls the given function. This means a SwfdecAsFrame is created for the function and pushed on top of the execution stack. The function is however not executed. Call swfdec_as_context_run() to execute it.

function : the SwfdecAsFunction to call
thisp : this argument to use for the call or NULL for none
n_args : number of arguments to pass to the function
args : the arguments to pass or NULL to read the last n_args stack elements
return_value : pointer for return value or NULL to push the return value to the stack

swfdec_as_native_function_new ()

SwfdecAsFunction*   swfdec_as_native_function_new       (SwfdecAsContext *context,
                                                         const char *name,
                                                         SwfdecAsNative native,
                                                         guint min_args);

Creates a new native function, that will execute native when called. The min_args parameter sets a requirement for the minimum number of arguments to pass to native. If the function gets called with less arguments, it will just redurn undefined. You might want to use swfdec_as_object_add_function() instead of this function.

context : a SwfdecAsContext
name : name of the function
native : function to call when executed
min_args : minimum number of arguments required
Returns : a new SwfdecAsFunction or NULL on OOM

swfdec_as_native_function_set_construct_type ()

void                swfdec_as_native_function_set_construct_type
                                                        (SwfdecAsNativeFunction *function,
                                                         GType type);

Sets the type to be used when using function as a constructor. If this is not set, using function as a constructor will create a SwfdecAsObject.

function : a SwfdecAsNativeFunction
type : GType used when constructing an object with function

swfdec_as_native_function_set_object_type ()

void                swfdec_as_native_function_set_object_type
                                                        (SwfdecAsNativeFunction *function,
                                                         GType type);

Sets the required type for the this object to type. If the this object isn't of the required type, the function will not be called and its return value will be undefined.

function : a SwfdecAsNativeFunction
type : required GType for the this object