static int swfdec_as_array_sort_compare (gconstpointer a_ptr, gconstpointer b_ptr, gpointer user_data) { const SwfdecAsValue *a = &((SortEntry *)a_ptr)->value; const SwfdecAsValue *b = &((SortEntry *)b_ptr)->value; SortCompareData *data = user_data; int retval; g_return_val_if_fail (SWFDEC_IS_AS_VALUE (a), 0); g_return_val_if_fail (SWFDEC_IS_AS_VALUE (b), 0); g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (data->context), 0); g_return_val_if_fail (data->options != NULL, 0); g_return_val_if_fail (data->custom_function == NULL || SWFDEC_IS_AS_FUNCTION (data->custom_function), 0); g_return_val_if_fail (data->fields == NULL || data->fields[0] != NULL, 0); if (data->fields == NULL) { retval = swfdec_as_array_sort_compare_values (data->context, a, b, data->options[0], data->custom_function); } else { SwfdecAsValue a_comp, b_comp; SwfdecAsObject *object; int i; i = 0; do { object = swfdec_as_value_to_object (data->context, a); if (object) { swfdec_as_object_get_variable (object, data->fields[i], &a_comp); } else { SWFDEC_AS_VALUE_SET_UNDEFINED (&a_comp); } object = swfdec_as_value_to_object (data->context, b); if (object) { swfdec_as_object_get_variable (object, data->fields[i], &b_comp); } else { SWFDEC_AS_VALUE_SET_UNDEFINED (&b_comp); } retval = swfdec_as_array_sort_compare_values (data->context, &a_comp, &b_comp, data->options[i], data->custom_function); } while (retval == 0 && data->fields[++i] != NULL); } if (retval == 0) data->equal_found = TRUE; return retval; }
void broadcastMessage (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret) { SwfdecAsValue val; SwfdecAsObject *listeners, *o; gint i, length; const char *name; GSList *list = NULL, *walk; if (object == NULL) return; if (argc < 1) return; name = swfdec_as_value_to_string (cx, argv[0]); argv += 1; argc--; swfdec_as_object_get_variable (object, SWFDEC_AS_STR__listeners, &val); if (!SWFDEC_AS_VALUE_IS_COMPOSITE (val)) return; listeners = SWFDEC_AS_VALUE_GET_COMPOSITE (val); swfdec_as_object_get_variable (listeners, SWFDEC_AS_STR_length, &val); length = swfdec_as_value_to_integer (cx, val); /* return undefined if we won't try to call anything */ if (length <= 0) return; /* FIXME: solve this wth foreach, so it gets faster for weird cases */ for (i = 0; i < length; i++) { swfdec_as_object_get_variable (listeners, swfdec_as_integer_to_string (cx, i), &val); o = swfdec_as_value_to_object (cx, val); if (o == NULL) continue; list = g_slist_prepend (list, o); } if (list == NULL) return; list = g_slist_reverse (list); for (walk = list; walk; walk = walk->next) { swfdec_as_object_call (walk->data, name, argc, argv, &val); } g_slist_free (list); SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE); }
/** * swfdec_as_native_function_checkv: * @cx: a #SwfdecAsContext * @object: this object passed to the native function * @type: expected type of @object * @result: pointer to variable taking cast result of @object * @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 * * This is the valist version of swfdec_as_native_function_check(). See that * function for details. * * Returns: %TRUE if the conversion succeeded, %FALSE otherwise **/ gboolean swfdec_as_native_function_checkv (SwfdecAsContext *cx, SwfdecAsObject *object, GType type, gpointer *result, guint argc, SwfdecAsValue *argv, const char *args, va_list varargs) { guint i; gboolean optional = FALSE; g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (cx), FALSE); g_return_val_if_fail (type == 0 || result != NULL, FALSE); /* check that we got a valid type */ if (type) { if (G_TYPE_CHECK_INSTANCE_TYPE (object, type)) { *result = object; } else if (object && G_TYPE_CHECK_INSTANCE_TYPE (object->relay, type)) { *result = object->relay; } else { return FALSE; } } for (i = 0; *args && i < argc; i++, args++) { switch (*args) { case 'v': { SwfdecAsValue *val = va_arg (varargs, SwfdecAsValue *); *val = argv[i]; } break; case 'b': { gboolean *b = va_arg (varargs, gboolean *); *b = swfdec_as_value_to_boolean (cx, argv[i]); } break; case 'i': { int *j = va_arg (varargs, int *); *j = swfdec_as_value_to_integer (cx, argv[i]); } break; case 'm': case 'M': { SwfdecMovie *m; SwfdecMovie **arg = va_arg (varargs, SwfdecMovie **); if (SWFDEC_AS_VALUE_IS_MOVIE (argv[i])) { m = SWFDEC_AS_VALUE_GET_MOVIE (argv[i]); } else { m = NULL; } if (m == NULL && *args != 'M') return FALSE; *arg = m; } break; case 'n': { double *d = va_arg (varargs, double *); *d = swfdec_as_value_to_number (cx, argv[i]); } break; case 's': { const char **s = va_arg (varargs, const char **); *s = swfdec_as_value_to_string (cx, argv[i]); } break; case 'o': case 'O': { SwfdecAsObject **o = va_arg (varargs, SwfdecAsObject **); *o = swfdec_as_value_to_object (cx, argv[i]); if (*o == NULL && *args != 'O') return FALSE; } break; case '|': g_return_val_if_fail (optional == FALSE, FALSE); optional = TRUE; i--; break; default: g_warning ("'%c' is not a valid type conversion", *args); return FALSE; } } if (*args && !optional && *args != '|') return FALSE; return TRUE; }