/** * swfdec_as_native_function_new: * @context: a #SwfdecAsContext * @name: name of the function * @native: function to call when executed * @prototype: The object to be used as "prototype" property for the created * function or %NULL for none. * * 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. * * Returns: a new #SwfdecAsFunction **/ SwfdecAsFunction * swfdec_as_native_function_new (SwfdecAsContext *context, const char *name, SwfdecAsNative native, SwfdecAsObject *prototype) { SwfdecAsNativeFunction *fun; g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), NULL); g_return_val_if_fail (native != NULL, NULL); g_return_val_if_fail (prototype == NULL || SWFDEC_IS_AS_OBJECT (prototype), NULL); fun = g_object_new (SWFDEC_TYPE_AS_NATIVE_FUNCTION, "context", context, NULL); fun->native = native; fun->name = g_strdup (name); /* need to set prototype before setting the constructor or Function.constructor * being CONSTANT disallows setting it. */ if (prototype) { SwfdecAsValue val; SWFDEC_AS_VALUE_SET_OBJECT (&val, prototype); swfdec_as_object_set_variable_and_flags (SWFDEC_AS_OBJECT (fun), SWFDEC_AS_STR_prototype, &val, SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT); } swfdec_as_function_set_constructor (SWFDEC_AS_FUNCTION (fun)); return SWFDEC_AS_FUNCTION (fun); }
void swfdec_bitmap_data_get_rectangle (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret) { SwfdecBitmapData *bitmap; SwfdecAsObject *o; SwfdecAsValue args[4]; SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, ""); SWFDEC_AS_VALUE_SET_INT (ret, -1); if (bitmap->surface == NULL) return; swfdec_as_object_get_variable (cx->global, SWFDEC_AS_STR_flash, args); if (!SWFDEC_AS_VALUE_IS_OBJECT (args)) return; o = SWFDEC_AS_VALUE_GET_OBJECT (args); swfdec_as_object_get_variable (o, SWFDEC_AS_STR_geom, args); if (!SWFDEC_AS_VALUE_IS_OBJECT (args)) return; o = SWFDEC_AS_VALUE_GET_OBJECT (args); swfdec_as_object_get_variable (o, SWFDEC_AS_STR_Rectangle, args); if (!SWFDEC_AS_VALUE_IS_OBJECT (args)) return; o = SWFDEC_AS_VALUE_GET_OBJECT (args); if (!SWFDEC_IS_AS_FUNCTION (o)) return; SWFDEC_AS_VALUE_SET_INT (&args[0], 0); SWFDEC_AS_VALUE_SET_INT (&args[1], 0); SWFDEC_AS_VALUE_SET_INT (&args[2], cairo_image_surface_get_width (bitmap->surface)); SWFDEC_AS_VALUE_SET_INT (&args[3], cairo_image_surface_get_height (bitmap->surface)); swfdec_as_object_create (SWFDEC_AS_FUNCTION (o), 4, args, ret); }
SwfdecAsFunction * swfdec_as_native_function_new_bare (SwfdecAsContext *context, const char *name, SwfdecAsNative native) { SwfdecAsNativeFunction *fun; SwfdecAsObject *object; g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), NULL); g_return_val_if_fail (native != NULL, NULL); fun = g_object_new (SWFDEC_TYPE_AS_NATIVE_FUNCTION, "context", context, NULL); fun->native = native; fun->name = g_strdup (name); object = swfdec_as_object_new_empty (context); swfdec_as_object_set_relay (object, SWFDEC_AS_RELAY (fun)); return SWFDEC_AS_FUNCTION (fun); }