Swfdec Reference Manual | ||||
---|---|---|---|---|
#include <swfdec/swfdec.h> enum SwfdecAsValueType; SwfdecAsValue; #define SWFDEC_AS_VALUE_SET_UNDEFINED (val) #define SWFDEC_AS_VALUE_GET_BOOLEAN (val) gboolean swfdec_as_value_to_boolean (SwfdecAsContext *context, const SwfdecAsValue *value); #define SWFDEC_AS_VALUE_SET_BOOLEAN (val,b) #define SWFDEC_AS_VALUE_GET_NUMBER (val) double swfdec_as_value_to_number (SwfdecAsContext *context, const SwfdecAsValue *value); int swfdec_as_value_to_integer (SwfdecAsContext *context, const SwfdecAsValue *value); #define SWFDEC_AS_VALUE_SET_INT (val,d) #define SWFDEC_AS_VALUE_SET_NUMBER (val,d) #define SWFDEC_AS_VALUE_GET_STRING (val) const char* swfdec_as_value_to_string (SwfdecAsContext *context, const SwfdecAsValue *value); #define SWFDEC_AS_VALUE_SET_STRING (val,s) #define SWFDEC_AS_VALUE_SET_NULL (val) #define SWFDEC_AS_VALUE_GET_OBJECT (val) SwfdecAsObject* swfdec_as_value_to_object (SwfdecAsContext *context, const SwfdecAsValue *value); #define SWFDEC_AS_VALUE_SET_OBJECT (val,o) void swfdec_as_value_to_primitive (SwfdecAsValue *value); char* swfdec_as_value_to_debug (const SwfdecAsValue *value); int swfdec_as_double_to_integer (double d); const char* swfdec_as_double_to_string (SwfdecAsContext *context, double d); const char* swfdec_as_integer_to_string (SwfdecAsContext *context, int i); const char* swfdec_as_str_concat (SwfdecAsContext *cx, const char *s1, const char *s2);
This section describes how values are handled inside the Actionscript
engine. Since Actionscript is a dynamically typed language, the variable type
has to be carried with every value. SwfdecAsValue accomplishes that. Swfdec
allows two possible ways of accessing these values: The common method is to
use the provided functions to explicitly convert the values to a given type
with a function such as swfdec_as_value_to_string()
. This is convenient,
but can be very slow as it can call back into the Actionscript engine when
converting various objects. So it can be unsuitable in some cases.
A different possibiltiy is accessing the values directly using the accessor
macros. You must check the type before doing so though. For setting values,
there only exist macros, since type conversion is not necessary.
typedef enum { SWFDEC_AS_TYPE_UNDEFINED = 0, SWFDEC_AS_TYPE_BOOLEAN, SWFDEC_AS_TYPE_INT, /* unimplemented, but reserved if someone wants it */ SWFDEC_AS_TYPE_NUMBER, SWFDEC_AS_TYPE_STRING, SWFDEC_AS_TYPE_NULL, SWFDEC_AS_TYPE_OBJECT } SwfdecAsValueType;
These are the possible values the Swfdec Actionscript engine knows about.
the special undefined value | |
a boolean value - true or false | |
reserved value for integers. Should the need arise for performance enhancements - especially on embedded devices - it might be useful to implement this type. For now, this type will never appear in Swfdec. Using it will cause Swfdec to crash. | |
a double value - also used for integer numbers | |
a string. Strings are garbage-collected and unique. | |
the spaecial null value | |
an object - must be of type SwfdecAsObject |
typedef struct { SwfdecAsValueType type; } SwfdecAsValue;
This is the type used to present an opaque value in the Actionscript engine. See SwfdecAsValueType for possible types. It's similar in spirit to GValue. The value held is garbage-collected. Apart from the type member, use the provided macros to access this structure.
SwfdecAsValueType |
the type of this value. |
#define SWFDEC_AS_VALUE_SET_UNDEFINED(val) (val)->type = SWFDEC_AS_TYPE_UNDEFINED
Sets val
to the special undefined value. If you create a temporary value,
you can instead use code such as
SwfdecAsValue val = { 0, };
|
value to set as undefined |
#define SWFDEC_AS_VALUE_GET_BOOLEAN(val) ((val)->value.boolean)
Gets the boolean associated with value. If you are not sure if the value is
a boolean, use swfdec_as_value_to_boolean()
instead.
|
value to get, the value must reference a boolean |
gboolean swfdec_as_value_to_boolean (SwfdecAsContext *context, const SwfdecAsValue *value);
Converts the given value to a boolean according to Flash's rules. Note that these rules changed significantly for strings between Flash 6 and 7.
|
a SwfdecAsContext |
|
value to convert |
Returns : |
either TRUE or FALSE .
|
#define SWFDEC_AS_VALUE_SET_BOOLEAN(val,b)
Sets val
to the specified boolean value.
#define SWFDEC_AS_VALUE_GET_NUMBER(val) ((val)->value.number)
Gets the number associated with val
. If you are not sure that the value is
a valid number value, consider using swfdec_as_value_to_number()
or
swfdec_as_value_to_int()
instead.
|
value to get, the value must reference a number |
double swfdec_as_value_to_number (SwfdecAsContext *context, const SwfdecAsValue *value);
Converts the value to a number according to Flash's conversion routines and the current Flash version. This conversion routine is similar, but not equal to ECMAScript. For objects, it can call back into the script engine by calling the object's valueOf function.
|
a SwfdecAsContext |
|
a SwfdecAsValue used by context |
Returns : |
a double value. It can be NaN or +-Infinity. It will not be -0.0. |
int swfdec_as_value_to_integer (SwfdecAsContext *context, const SwfdecAsValue *value);
Converts the given value to an integer. This is done similar to the
conversion used by swfdec_as_value_to_number()
.
|
a SwfdecAsContext |
|
value to convert |
Returns : |
An Integer that can be represented in 32 bits. |
#define SWFDEC_AS_VALUE_SET_INT(val,d) SWFDEC_AS_VALUE_SET_NUMBER(val,(int) (d))
Sets val
to the given value. Currently this macro is equivalent to
SWFDEC_AS_VALUE_SET_NUMBER()
, but this may change in future versions of
Swfdec.
|
value to set |
|
integer value to set |
#define SWFDEC_AS_VALUE_SET_NUMBER(val,d)
Sets val
to the given value. If you are sure the value is a valid
integer value, use SWFDEC_AS_VALUE_SET_INT()
instead.
|
value to set |
|
double value to set |
#define SWFDEC_AS_VALUE_GET_STRING(val) ((val)->value.string)
Gets the string associated with val
. If you are not sure that the value is
a string value, consider using swfdec_as_value_to_string()
instead.
|
value to get, the value must reference a string |
const char* swfdec_as_value_to_string (SwfdecAsContext *context, const SwfdecAsValue *value);
Converts value
to a string according to the rules of Flash. This might
cause calling back into the script engine if the value
is an object. In
that case, the object's valueOf function is called.
|
a SwfdecAsContext |
|
value to be expressed as string |
Returns : |
a garbage-collected string representing value . The value will
never be NULL .
|
#define SWFDEC_AS_VALUE_SET_STRING(val,s)
Sets val
to the given string value.
|
value to set |
|
garbage-collected string to use |
#define SWFDEC_AS_VALUE_SET_NULL(val) (val)->type = SWFDEC_AS_TYPE_NULL
Sets val
to the special null value.
|
value to set |
#define SWFDEC_AS_VALUE_GET_OBJECT(val)
Gets the object associated with val
. If you are not sure that the value is
an object value, consider using swfdec_as_value_to_object()
instead.
|
value to get, the value must reference an object |
Returns : |
a SwfdecAsObject |
SwfdecAsObject* swfdec_as_value_to_object (SwfdecAsContext *context, const SwfdecAsValue *value);
Converts a given value to its representation as an object. The object
representation for primitive types is a wrapper object of the corresponding
class (Number for numbers, String for strings, Boolean for bools). If the
value does not have an object representing it, such as undefined and null
values, NULL
is returned.
|
a SwfdecAsContext |
|
value to convert |
Returns : |
object representing value or NULL .
|
#define SWFDEC_AS_VALUE_SET_OBJECT(val,o)
Sets val
to the given object. The object must have been added to the
garbage collector via swfdec_as_object_add()
previously.
|
value to set |
|
garbage-collected SwfdecAsObject to use |
void swfdec_as_value_to_primitive (SwfdecAsValue *value);
Tries to convert the given value
inline to its primitive value. Primitive
values are values that are not objects. If the value is an object, the
object's valueOf function is called. If the result of that function is still
an object, it is returned nonetheless.
|
value to convert |
char* swfdec_as_value_to_debug (const SwfdecAsValue *value);
Converts the given value
to a string in a safe way. It will not call into
the scripting engine. Its intended use is for output in debuggers.
|
a SwfdecAsValue |
Returns : |
a newly allocated string. Free with g_free() .
|
int swfdec_as_double_to_integer (double d);
Converts the given double to an integer using the same rules as the Flash player.
|
any double |
Returns : |
an integer |
const char* swfdec_as_double_to_string (SwfdecAsContext *context, double d);
Converts d
into a string using the same conversion algorithm as the
official Flash player.
|
a SwfdecAsContext |
|
a double |
Returns : |
a garbage-collected string |
const char* swfdec_as_integer_to_string (SwfdecAsContext *context, int i);
Converts d
into a string using the same conversion algorithm as the
official Flash player.
|
a SwfdecAsContext |
|
an integer that fits into 32 bits |
Returns : |
a garbage-collected string |
const char* swfdec_as_str_concat (SwfdecAsContext *cx, const char *s1, const char *s2);
Convenience function to concatenate two garbage-collected strings. This
function is equivalent to g_strconcat()
.
|
a SwfdecAsContext |
|
first string |
|
second string |
Returns : |
A new garbage-collected string |