SwfdecAsFunction3SWFDEC LibrarySwfdecAsFunctionscript objects that can be executedFunctionsvoid(*SwfdecAsNative)()#defineswfdec_as_function_call()voidswfdec_as_function_call_full ()SwfdecAsFunction *
swfdec_as_native_function_new ()voidswfdec_as_native_function_set_construct_type ()gbooleanswfdec_as_native_function_check ()gbooleanswfdec_as_native_function_checkv ()#defineSWFDEC_AS_CHECK()Types and ValuesSwfdecAsFunctionstructSwfdecAsNativeFunctionObject Hierarchy GObject
╰── SwfdecGcObject
╰── SwfdecAsObject
╰── SwfdecAsFunction
╰── SwfdecAsNativeFunction
Includes#include <swfdec/swfdec.h>
DescriptionFunctions 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().FunctionsSwfdecAsNative ()SwfdecAsNativevoid(*SwfdecAsNative) (SwfdecAsContext *context,
SwfdecAsObject *thisp,
guint argc,
SwfdecAsValue *argv,
SwfdecAsValue *retval);This is the prototype for all native functions.ParameterscontextSwfdecAsContextthispthe this object. Can be NULL.argcnumber of arguments passed to this functionargvthe argc
arguments passed to this functionretvalset to the return value. Initialized to undefined by defaultswfdec_as_function_call()swfdec_as_function_call#define swfdec_as_function_call(function, thisp, n_args, args, return_value)Calls the given function. This is a macro that resolves to
swfdec_as_function_call_full().Parametersfunctionthe SwfdecAsFunction to callthispthis argument to use for the call or NULL for nonen_argsnumber of arguments to pass to the functionargsthe arguments to pass or NULL to read the last n_args
stack elements.return_valuepointer for return value or NULL to push the return value to
the stackswfdec_as_function_call_full ()swfdec_as_function_call_fullvoid
swfdec_as_function_call_full (SwfdecAsFunction *function,
SwfdecAsObject *thisp,
gboolean construct,
SwfdecAsObject *super_reference,
guint n_args,
const SwfdecAsValue *args,
SwfdecAsValue *return_value);Calls the given function.Parametersfunctionthe SwfdecAsFunction to callthispthis argument to use for the call or NULL for noneconstructcall this function as a constructor. This is only relevant for
native functions.super_referenceThe object to be referenced by the super object in this
function call or NULL to use the default.n_argsnumber of arguments to pass to the functionargsthe arguments to pass or NULL to read the last n_args
stack elements.return_valuepointer for return value or NULL to push the return value to
the stackswfdec_as_native_function_new ()swfdec_as_native_function_newSwfdecAsFunction *
swfdec_as_native_function_new (SwfdecAsContext *context,
const char *name,
SwfdecAsNative native,
SwfdecAsObject *prototype);Creates a new native function, that will execute native
when called. You
might want to use swfdec_as_object_add_function() instead of this function.Parameterscontexta SwfdecAsContextnamename of the functionnativefunction to call when executedprototypeThe object to be used as "prototype" property for the created
function or NULL for none.Returns a new SwfdecAsFunctionswfdec_as_native_function_set_construct_type ()swfdec_as_native_function_set_construct_typevoid
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.Parametersfunctiona SwfdecAsNativeFunctiontypeGType used when constructing an object with functionswfdec_as_native_function_check ()swfdec_as_native_function_checkgboolean
swfdec_as_native_function_check (SwfdecAsContext *cx,
SwfdecAsObject *object,
GType type,
gpointer *result,
guint argc,
SwfdecAsValue *argv,
const char *args,
...);
This function is a convenience function to validate and convert arguments to
a native function while avoiding common pitfalls. You typically want to call
it at the beginning of every native function you write. Or you can use the
SWFDEC_AS_CHECK() macro instead which calls this function.
The cx
, object
, argc
and argv
paramters should be passed verbatim from
the function call to your native function. If type
is not 0, object
is then
checked to be of that type and cast to result
. After that the args
string
is used to convert the arguments. Every character in args
describes the
conversion of one argument. For that argument, you have to pass a pointer
that takes the value. For the conversion, the default conversion functions
like swfdec_as_value_to_string() are used. If not enough arguments are
available, the function stops converting and returns NULL. The following
conversion characters are allowed:"b": convert to boolean. Requires a gboolean pointer
"i": convert to integer. Requires an integer pointer
"n": convert to number. Requires a double pointer
"o": convert to object. Requires a SwfdecAsObject pointer.
If the conversion fails, this function immediately returns
FALSE."O": convert to object or NULL. Requires a SwfdecAsObject
pointer."s": convert to garbage-collected string. Requires a const
char pointer"v": copy the value. The given argument must be a pointer
to a SwfdecAsValue"|": optional arguments follow. Optional arguments will be
initialized to the empty value for their type. This
conversion character is only allowed once in the conversion
string.Parameterscxa SwfdecAsContextobjectthis object passed to the native functiontypeexpected type of object
or 0 for anyresultpointer to variable taking cast result of objectargccount of arguments passed to the functionargvarguments passed to the functionargsargument conversion string...pointers to variables taking converted argumentsReturnsTRUE if the conversion succeeded, FALSE otherwiseswfdec_as_native_function_checkv ()swfdec_as_native_function_checkvgboolean
swfdec_as_native_function_checkv (SwfdecAsContext *cx,
SwfdecAsObject *object,
GType type,
gpointer *result,
guint argc,
SwfdecAsValue *argv,
const char *args,
va_list varargs);This is the valist version of swfdec_as_native_function_check(). See that
function for details.Parameterscxa SwfdecAsContextobjectthis object passed to the native functiontypeexpected type of objectresultpointer to variable taking cast result of objectargccount of arguments passed to the functionargvarguments passed to the functionargsargument conversion stringvarargspointers to variables taking converted argumentsReturnsTRUE if the conversion succeeded, FALSE otherwiseSWFDEC_AS_CHECK()SWFDEC_AS_CHECK#define SWFDEC_AS_CHECK(type,result,...)This is a shortcut macro for calling swfdec_as_native_function_check() at
the beginning of a native function. See that function for details.
It requires the native function parameters to have the default name. So your
function must be declared like this:Parameterstyperequired type of this object or 0 for ignoringresultconverted this object...conversion string and pointers taking converted valuesTypes and ValuesSwfdecAsFunctionSwfdecAsFunctiontypedef struct _SwfdecAsFunction SwfdecAsFunction;This is the base executable object in Swfdec. It is an abstract object. If
you want to create functions yourself, use SwfdecAsNativeFunction.struct SwfdecAsNativeFunctionSwfdecAsNativeFunctionstruct SwfdecAsNativeFunction;This is the object type for native functions.