static SeedValue seed_cairo_surface_write_to_png (SeedContext ctx, SeedObject function, SeedObject this_object, gsize argument_count, const SeedValue arguments[], SeedException *exception) { cairo_status_t ret; cairo_surface_t *surf; gchar *filename; CHECK_THIS(); if (argument_count != 1) { EXPECTED_EXCEPTION("write_to_png", "1 argument"); } surf = seed_object_get_private (this_object); filename = seed_value_to_string (ctx, arguments[0], exception); ret = cairo_surface_write_to_png (surf, filename); g_free (filename); return seed_value_from_long (ctx, ret, exception); }
static SeedValue seed_cairo_surface_get_type (SeedContext ctx, SeedObject this_object, SeedString property_name, SeedException *exception) { CHECK_THIS(); return seed_value_from_long (ctx, cairo_surface_get_type (seed_object_to_cairo_surface(ctx, this_object, exception)), exception); }
static SeedValue value_from_ffi_type (SeedContext ctx, GType otype, GArgument *value, SeedException *exception) { switch (g_type_fundamental (otype)) { case G_TYPE_INT: return seed_value_from_int (ctx, value->v_int, exception); break; case G_TYPE_FLOAT: return seed_value_from_float (ctx, value->v_float, exception); break; case G_TYPE_DOUBLE: return seed_value_from_double (ctx, value->v_double, exception); break; case G_TYPE_BOOLEAN: return seed_value_from_boolean (ctx, value->v_boolean, exception); break; case G_TYPE_STRING: return seed_value_from_string (ctx, value->v_pointer, exception); break; case G_TYPE_CHAR: return seed_value_from_char (ctx, value->v_int, exception); break; case G_TYPE_UCHAR: return seed_value_from_uchar (ctx, value->v_uint, exception); break; case G_TYPE_UINT: return seed_value_from_uint (ctx, value->v_uint, exception); break; case G_TYPE_POINTER: return seed_make_pointer (ctx, value->v_pointer); break; case G_TYPE_LONG: return seed_value_from_long (ctx, value->v_long, exception); break; case G_TYPE_ULONG: return seed_value_from_ulong (ctx, value->v_ulong, exception); break; case G_TYPE_INT64: return seed_value_from_int64 (ctx, value->v_int64, exception); break; case G_TYPE_UINT64: return seed_value_from_uint64 (ctx, value->v_uint64, exception); break; case G_TYPE_NONE: return seed_make_null (ctx); default: g_warning ("Unsupported fundamental type in value_from_ffi_type: %s", g_type_name(g_type_fundamental (otype))); return seed_make_null (ctx); } }
static void seed_gi_importer_handle_iface(JSContextRef ctx, JSObjectRef namespace_ref, GIObjectInfo* info, JSValueRef* exception) { GType type; type = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) info); if (type != 0) { GIFunctionInfo* finfo; GIFunctionInfoFlags flags; JSObjectRef constructor_ref; guint i, n_methods; constructor_ref = JSObjectMake(ctx, gobject_constructor_class, (gpointer) type); seed_object_set_property(ctx, constructor_ref, "type", seed_value_from_long(ctx, type, exception)); n_methods = g_interface_info_get_n_methods(info); for (i = 0; i < n_methods; i++) { finfo = g_interface_info_get_method(info, i); flags = g_function_info_get_flags(finfo); if (!(flags & GI_FUNCTION_IS_METHOD)) { seed_gobject_define_property_from_function_info(ctx, finfo, constructor_ref, FALSE); } else { g_base_info_unref((GIBaseInfo*) finfo); } } seed_object_set_property(ctx, namespace_ref, g_base_info_get_name((GIBaseInfo*) info), constructor_ref); seed_object_set_property(ctx, constructor_ref, "prototype", seed_gobject_get_prototype_for_gtype(type)); } }
static gboolean gio_marshal_func(GIOChannel * source, GIOCondition condition, gpointer data) { SeedGlobalContext ctx = seed_context_create(eng->group, 0); SeedValue jscondition = seed_value_from_long(ctx, (glong) condition, 0); SeedValue args[3], ret; marshal_privates *priv = (marshal_privates *) data; gboolean bret; args[0] = priv->source; args[1] = jscondition; args[2] = priv->user_data; ret = seed_object_call(ctx, priv->function, 0, 3, args, 0); bret = seed_value_to_boolean(ctx, ret, 0); seed_context_unref(ctx); if (!bret) g_free(priv); return bret; }
/* * Handle setting up the prototype and constructor for a GObject type * Namespace.Type will be the constructor and Namespace.Type.prototype is * the prototype object. Namespace.Type.type will be the GType. */ static void seed_gi_importer_handle_object(JSContextRef ctx, JSObjectRef namespace_ref, GIObjectInfo* info, JSValueRef* exception) { GType type; JSClassRef class_ref; type = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) info); if (type != 0) { GIFunctionInfo* finfo; GIFunctionInfoFlags flags; JSObjectRef constructor_ref; guint i, n_methods; class_ref = seed_gobject_get_class_for_gtype(ctx, type); constructor_ref = JSObjectMake(ctx, gobject_constructor_class, (gpointer) type); seed_object_set_property(ctx, constructor_ref, "type", seed_value_from_long(ctx, type, exception)); n_methods = g_object_info_get_n_methods(info); for (i = 0; i < n_methods; i++) { finfo = g_object_info_get_method(info, i); flags = g_function_info_get_flags(finfo); if (flags & GI_FUNCTION_IS_CONSTRUCTOR) { JSObjectRef constructor = JSObjectMake(ctx, gobject_named_constructor_class, finfo); const gchar* fname = g_base_info_get_name((GIBaseInfo*) finfo); if (g_strrstr(fname, "new_") == fname) { // To be compatible with gjs, we need to have a method with // new_, too. seed_object_set_property(ctx, constructor_ref, fname, constructor); fname += 4; } else if (!g_strcmp0(fname, "new")) { // To be compatible with gjs, we need to have new as // function, too. seed_object_set_property(ctx, constructor_ref, fname, constructor); fname = "c_new"; } seed_object_set_property(ctx, constructor_ref, fname, constructor); } else if (!(flags & GI_FUNCTION_IS_METHOD)) { seed_gobject_define_property_from_function_info(ctx, finfo, constructor_ref, FALSE); } else { g_base_info_unref((GIBaseInfo*) finfo); } } seed_object_set_property(ctx, namespace_ref, g_base_info_get_name((GIBaseInfo*) info), constructor_ref); seed_object_set_property(ctx, constructor_ref, "prototype", seed_gobject_get_prototype_for_gtype(type)); } }
void basic_types(TestSimpleFixture * fixture, gconstpointer _data) { // bool to/from JS equality gboolean bool_test_in = TRUE; SeedValue *bool_test = seed_value_from_boolean(fixture->context, bool_test_in, NULL); gboolean bool_test_out = seed_value_to_boolean(fixture->context, bool_test, NULL); g_assert(bool_test_in == bool_test_out); // uint to/from JS equality guint uint_test_in = 2946623; SeedValue *uint_test = seed_value_from_uint(fixture->context, uint_test_in, NULL); guint uint_test_out = seed_value_to_uint(fixture->context, uint_test, NULL); g_assert(uint_test_in == uint_test_out); // int to/from JS equality gint int_test_in = -54374; SeedValue *int_test = seed_value_from_int(fixture->context, int_test_in, NULL); gint int_test_out = seed_value_to_int(fixture->context, int_test, NULL); g_assert(int_test_in == int_test_out); // char to/from JS equality gchar char_test_in = -126; SeedValue *char_test = seed_value_from_char(fixture->context, char_test_in, NULL); gchar char_test_out = seed_value_to_char(fixture->context, char_test, NULL); g_assert(char_test_in == char_test_out); // uchar to/from JS equality guchar uchar_test_in = 250; SeedValue *uchar_test = seed_value_from_uchar(fixture->context, uchar_test_in, NULL); guchar uchar_test_out = seed_value_to_uchar(fixture->context, uchar_test, NULL); g_assert(uchar_test_in == uchar_test_out); // long to/from JS equality glong long_test_in = -454250; SeedValue *long_test = seed_value_from_long(fixture->context, long_test_in, NULL); glong long_test_out = seed_value_to_long(fixture->context, long_test, NULL); g_assert(long_test_in == long_test_out); // ulong to/from JS equality gulong ulong_test_in = 250; SeedValue *ulong_test = seed_value_from_ulong(fixture->context, ulong_test_in, NULL); gulong ulong_test_out = seed_value_to_ulong(fixture->context, ulong_test, NULL); g_assert(ulong_test_in == ulong_test_out); // int64 to/from JS equality gint64 int64_test_in = -54374; SeedValue *int64_test = seed_value_from_int64(fixture->context, int64_test_in, NULL); gint64 int64_test_out = seed_value_to_int64(fixture->context, int64_test, NULL); g_assert(int64_test_in == int64_test_out); // uint64 to/from JS equality guint64 uint64_test_in = 2946623; SeedValue *uint64_test = seed_value_from_uint64(fixture->context, uint64_test_in, NULL); guint64 uint64_test_out = seed_value_to_uint64(fixture->context, uint64_test, NULL); g_assert(uint64_test_in == uint64_test_out); // float to/from JS equality gfloat float_test_in = 1.618; SeedValue *float_test = seed_value_from_float(fixture->context, float_test_in, NULL); gfloat float_test_out = seed_value_to_float(fixture->context, float_test, NULL); g_assert(float_test_in == float_test_out); // double to/from JS equality gdouble double_test_in = 1.6134857638; SeedValue *double_test = seed_value_from_double(fixture->context, double_test_in, NULL); gdouble double_test_out = seed_value_to_double(fixture->context, double_test, NULL); g_assert(double_test_in == double_test_out); // string to/from JS equality gchar *string_test_in = "Hello, world!"; SeedValue *string_test = seed_value_from_string(fixture->context, string_test_in, NULL); gchar *string_test_out = seed_value_to_string(fixture->context, string_test, NULL); g_assert(strncmp(string_test_in, string_test_out, strlen(string_test_in)) == 0); // filename to/from JS equality gchar *filename_test_in = "/bin"; SeedValue *filename_test = seed_value_from_filename(fixture->context, filename_test_in, NULL); gchar *filename_test_out = seed_value_to_filename(fixture->context, filename_test, NULL); g_assert(strncmp(filename_test_in, filename_test_out, strlen(filename_test_in)) == 0); SeedValue si[2]; si[0] = seed_value_from_string (fixture->context, "Hi", NULL); si[1] = seed_value_from_int (fixture->context, 1, NULL); gint ni; gchar *ns; seed_value_to_format (fixture->context, "si", si, NULL, &ns, &ni, NULL); g_assert (ni == 1); g_assert (!strcmp(ns, "Hi")); }