Top | ![]() |
![]() |
![]() |
![]() |
void | (*SwfdecAsNative) () |
#define | swfdec_as_function_call() |
void | swfdec_as_function_call_full () |
SwfdecAsFunction * | swfdec_as_native_function_new () |
gboolean | swfdec_as_native_function_check () |
gboolean | swfdec_as_native_function_checkv () |
#define | SWFDEC_AS_CHECK() |
GObject ╰── SwfdecGcObject ╰── SwfdecAsRelay ╰── SwfdecAsFunction ╰── SwfdecAsNativeFunction
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()
.
void (*SwfdecAsNative) (SwfdecAsContext *context
,SwfdecAsObject *thisp
,guint argc
,SwfdecAsValue *argv
,SwfdecAsValue *retval
);
This is the prototype for all native functions.
context |
||
thisp |
the this object. Can be
NULL . |
|
argc |
number of arguments passed to this function |
|
argv |
the |
|
retval |
set to the return value. Initialized to undefined by default |
#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()
.
function |
the SwfdecAsFunction to call |
|
thisp |
this argument to use for the call or |
|
n_args |
number of arguments to pass to the function |
|
args |
the arguments to pass or |
|
return_value |
pointer for return value or |
void 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.
function |
the SwfdecAsFunction to call |
|
thisp |
this argument to use for the call or |
|
construct |
call this function as a constructor. This is only relevant for native functions. |
|
super_reference |
The object to be referenced by the super object in this
function call or |
|
n_args |
number of arguments to pass to the function |
|
args |
the arguments to pass or |
|
return_value |
pointer for return value or |
SwfdecAsFunction * swfdec_as_native_function_new (SwfdecAsContext *context
,const char *name
,SwfdecAsNative native
);
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.
gboolean 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
"m": convert to an existing movieclip. This is only valid
inside Swfdec. Requires a SwfdecMovie
pointer.
"M": convert to a movieclip or NULL
. This is only valid
inside Swfdec. If the movie has already been destroyed,
the pointer will be set to NULL
"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.
cx |
||
object |
this object passed to the native function |
|
type |
expected type of |
|
result |
pointer to variable taking cast result of |
|
argc |
count of arguments passed to the function |
|
argv |
arguments passed to the function |
|
args |
argument conversion string |
|
... |
pointers to variables taking converted arguments |
gboolean 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.
cx |
||
object |
this object passed to the native function |
|
type |
expected type of |
|
result |
pointer to variable taking cast result of |
|
argc |
count of arguments passed to the function |
|
argv |
arguments passed to the function |
|
args |
argument conversion string |
|
varargs |
pointers to variables taking converted arguments |
#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:
1 2 |
my_function (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval);]| |
typedef 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.