seed r56 - trunk/libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r56 - trunk/libseed
- Date: Sun, 2 Nov 2008 08:38:09 +0000 (UTC)
Author: racarr
Date: Sun Nov 2 08:38:08 2008
New Revision: 56
URL: http://svn.gnome.org/viewvc/seed?rev=56&view=rev
Log:
Overhaul of argument conversion. As a free bonus, make things like
ClutterColor work.
Modified:
trunk/libseed/seed-engine.c
trunk/libseed/seed-structs.c
trunk/libseed/seed-structs.h
trunk/libseed/seed-types.c
Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c (original)
+++ trunk/libseed/seed-engine.c Sun Nov 2 08:38:08 2008
@@ -725,8 +725,42 @@
JSValueProtect(eng->context,
(JSValueRef)constructor_ref);
}
+ }
+ else if (info &&
+ (g_base_info_get_type(info) == GI_INFO_TYPE_STRUCT))
+ {
+ JSObjectRef struct_ref;
+ int i, n_methods;
+ GIFunctionInfo *finfo;
+ GIFunctionInfoFlags flags;
+
+ struct_ref = JSObjectMake(eng->context, 0, 0);
+
+ n_methods =
+ g_struct_info_get_n_methods((GIStructInfo *)info);
+ for (i = 0; i < n_methods; i++)
+ {
+ finfo =
+ g_struct_info_get_method(
+ (GIStructInfo*)info, i);
+ flags = g_function_info_get_flags(finfo);
+ if (flags & GI_FUNCTION_IS_CONSTRUCTOR)
+ {
+ seed_gobject_define_property_from_function_info(finfo,
+ struct_ref,
+ FALSE);
+ }
+ }
+
+ seed_value_set_property(namespace_ref,
+ g_base_info_get_name(info),
+ struct_ref);
+ JSValueProtect(eng->context,
+ (JSValueRef)struct_ref);
}
+
+
}
Modified: trunk/libseed/seed-structs.c
==============================================================================
--- trunk/libseed/seed-structs.c (original)
+++ trunk/libseed/seed-structs.c Sun Nov 2 08:38:08 2008
@@ -22,21 +22,16 @@
#include <string.h>
JSClassRef seed_struct_class = 0;
-typedef struct _SeedStructPrivates
-{
- gpointer object;
- GIBaseInfo * info;
-} SeedStructPrivates;
-static void seed_struct_finalize(JSObjectRef younion)
+static void seed_struct_finalize(JSObjectRef strukt)
{
- g_free(JSObjectGetPrivate(younion));
+ g_free(JSObjectGetPrivate(strukt));
}
JSClassDefinition gobject_struct_def = {
0, /* Version, always 0 */
0,
- "gobject_union", /* Class Name */
+ "seed_struct", /* Class Name */
NULL, /* Parent Class */
NULL, /* Static Values */
NULL, /* Static Functions */
@@ -53,21 +48,22 @@
NULL /* Convert To Type */
};
-JSObjectRef seed_make_union(gpointer younion, GIBaseInfo * info)
+gpointer seed_struct_get_pointer(JSValueRef strukt)
+{
+ if (JSValueIsObjectOfClass(eng->context, strukt, seed_struct_class))
+ return JSObjectGetPrivate((JSObjectRef)strukt);
+ return 0;
+}
+
+JSObjectRef seed_make_union(gpointer younion)
{
- SeedStructPrivates * privates;
if (!seed_struct_class)
seed_struct_class = JSClassCreate(&gobject_struct_def);
- privates = g_new0(SeedStructPrivates, 1);
-
- privates->object = younion;
- privates->info = info;
-
- return JSObjectMake(eng->context, seed_struct_class, privates);
+ return JSObjectMake(eng->context, seed_struct_class, younion);
}
-JSObjectRef seed_make_struct(gpointer strukt, GIBaseInfo * info)
+JSObjectRef seed_make_struct(gpointer strukt)
{
- return seed_make_union(strukt, info);
+ return seed_make_union(strukt);
}
Modified: trunk/libseed/seed-structs.h
==============================================================================
--- trunk/libseed/seed-structs.h (original)
+++ trunk/libseed/seed-structs.h Sun Nov 2 08:38:08 2008
@@ -20,7 +20,8 @@
#ifndef _SEED_STRUCT_H
#define _SEED_STRUCT_H
-JSObjectRef seed_make_union(gpointer younion, GIBaseInfo * info);
-JSObjectRef seed_make_struct(gpointer strukt, GIBaseInfo * info);
+JSObjectRef seed_make_union(gpointer younion);
+JSObjectRef seed_make_struct(gpointer strukt);
+gpointer seed_struct_get_pointer(JSValueRef strukt);
#endif
Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c (original)
+++ trunk/libseed/seed-types.c Sun Nov 2 08:38:08 2008
@@ -158,6 +158,8 @@
return G_TYPE_OBJECT;
else if (interface_type == GI_INFO_TYPE_ENUM)
return G_TYPE_LONG;
+ else if (interface_type == GI_INFO_TYPE_STRUCT)
+ return G_TYPE_POINTER;
}
}
return 0;
@@ -168,10 +170,8 @@
GITypeInfo *type_info,
GArgument * arg)
{
- GValue gval = {0};
GITypeTag gi_tag = g_type_info_get_tag(type_info);
- GType gtag = seed_gi_type_to_gtype(type_info,
- gi_tag);
+
if (!value || JSValueIsNull(eng->context, value))
{
@@ -179,63 +179,57 @@
return 1;
}
- seed_gvalue_from_seed_value(value,
- gtag,
- &gval);
-
switch(gi_tag)
{
case GI_TYPE_TAG_VOID:
break;
case GI_TYPE_TAG_BOOLEAN:
- arg->v_boolean = g_value_get_boolean(&gval);
+ arg->v_boolean = seed_value_to_boolean(value);
break;
case GI_TYPE_TAG_INT8:
- arg->v_int8 = g_value_get_char(&gval);
+ arg->v_int8 = seed_value_to_char(value);
break;
case GI_TYPE_TAG_UINT8:
- arg->v_uint8 = g_value_get_uchar(&gval);
+ arg->v_uint8 = seed_value_to_uchar(value);
break;
case GI_TYPE_TAG_INT16:
- arg->v_int16 = g_value_get_int(&gval);
+ arg->v_int16 = seed_value_to_int(value);
break;
case GI_TYPE_TAG_UINT16:
- arg->v_uint16 = g_value_get_uint(&gval);
+ arg->v_uint16 = seed_value_to_uint(value);
break;
case GI_TYPE_TAG_INT32:
- arg->v_int32 = g_value_get_int(&gval);
+ arg->v_int32 = seed_value_to_int(value);
break;
case GI_TYPE_TAG_UINT32:
- arg->v_uint32 = g_value_get_uint(&gval);
+ arg->v_uint32 = seed_value_to_uint(value);
break;
case GI_TYPE_TAG_LONG:
case GI_TYPE_TAG_INT64:
- arg->v_int64 = (gint64)g_value_get_long(&gval);
+ arg->v_int64 = seed_value_to_long(value);
break;
case GI_TYPE_TAG_ULONG:
case GI_TYPE_TAG_UINT64:
- arg->v_uint64 = (guint64)g_value_get_ulong(&gval);
+ arg->v_uint64 = seed_value_to_ulong(value);
break;
case GI_TYPE_TAG_INT:
- arg->v_int = g_value_get_int(&gval);
+ arg->v_int = seed_value_to_int(value);
break;
case GI_TYPE_TAG_UINT:
- arg->v_uint = g_value_get_uint(&gval);
- break;
- case GI_TYPE_TAG_SSIZE:
- arg->v_int = g_value_get_int(&gval);
+ arg->v_uint = seed_value_to_uint(value);
break;
case GI_TYPE_TAG_SIZE:
- arg->v_int = g_value_get_int(&gval);
+ case GI_TYPE_TAG_SSIZE:
+ arg->v_int = seed_value_to_int(value);
break;
case GI_TYPE_TAG_FLOAT:
- arg->v_float = g_value_get_float(&gval);
+ arg->v_float = seed_value_to_float(value);
break;
case GI_TYPE_TAG_DOUBLE:
- arg->v_double = g_value_get_double(&gval);
+ arg->v_double = seed_value_to_double(value);
break;
case GI_TYPE_TAG_UTF8:
- arg->v_string = g_strdup(g_value_get_string(&gval));
+ arg->v_string = seed_value_to_string(value);
break;
case GI_TYPE_TAG_INTERFACE:
{
@@ -252,11 +246,7 @@
if (interface_type == GI_INFO_TYPE_OBJECT
|| interface_type == GI_INFO_TYPE_INTERFACE)
{
- if (!G_VALUE_HOLDS_OBJECT(&gval))
- {
- return FALSE;
- }
- gobject = g_value_get_object(&gval);
+ gobject = seed_value_to_object(value);
required_gtype =
g_registered_type_info_get_g_type(
(GIRegisteredTypeInfo *) interface);
@@ -275,6 +265,11 @@
value, NULL);
break;
}
+ else if (interface_type == GI_INFO_TYPE_STRUCT)
+ {
+ arg->v_pointer = seed_struct_get_pointer(value);
+ break;
+ }
}
default:
@@ -290,66 +285,44 @@
JSValueRef seed_gi_argument_make_js(GArgument * arg, GITypeInfo *type_info)
{
- GValue gval = {0};
GITypeTag gi_tag = g_type_info_get_tag(type_info);
- GType gtag = seed_gi_type_to_gtype(type_info, gi_tag);
- SeedValue ret;
-
- g_value_init(&gval, gtag);
switch (gi_tag)
{
case GI_TYPE_TAG_VOID:
return 0;
case GI_TYPE_TAG_BOOLEAN:
- g_value_set_boolean(&gval,arg->v_boolean );
- break;
+ return seed_value_from_boolean(arg->v_boolean);
case GI_TYPE_TAG_INT8:
- g_value_set_char(&gval,arg->v_int8 );
- break;
+ return seed_value_from_char(arg->v_int8);
case GI_TYPE_TAG_UINT8:
- g_value_set_uchar(&gval,arg->v_uint8 );
- break;
+ return seed_value_from_uchar(arg->v_uint8);
case GI_TYPE_TAG_INT16:
- g_value_set_int(&gval,arg->v_int16 );
- break;
+ return seed_value_from_int(arg->v_int16);
case GI_TYPE_TAG_UINT16:
- g_value_set_uint(&gval,arg->v_uint16 );
- break;
+ return seed_value_from_uint(arg->v_uint16);
case GI_TYPE_TAG_INT32:
- g_value_set_int(&gval,arg->v_int32 );
- break;
+ return seed_value_from_int(arg->v_int32);
case GI_TYPE_TAG_UINT32:
- g_value_set_uint(&gval,arg->v_uint32 );
- break;
+ return seed_value_from_uint(arg->v_uint32);
case GI_TYPE_TAG_LONG:
case GI_TYPE_TAG_INT64:
- g_value_set_long(&gval,arg->v_int64);
- break;
+ return seed_value_from_long(arg->v_int64);
case GI_TYPE_TAG_ULONG:
case GI_TYPE_TAG_UINT64:
- g_value_set_ulong(&gval,arg->v_uint64);
- break;
+ return seed_value_from_ulong(arg->v_uint64);
case GI_TYPE_TAG_INT:
- g_value_set_int(&gval,arg->v_int );
- break;
+ return seed_value_from_int(arg->v_int32);
case GI_TYPE_TAG_UINT:
- g_value_set_uint(&gval,arg->v_uint );
- break;
+ return seed_value_from_uint(arg->v_uint32);
case GI_TYPE_TAG_SSIZE:
- g_value_set_int(&gval,arg->v_int );
- break;
case GI_TYPE_TAG_SIZE:
- g_value_set_int(&gval,arg->v_int );
- break;
+ return seed_value_from_int(arg->v_int);
case GI_TYPE_TAG_FLOAT:
- g_value_set_float(&gval,arg->v_float );
- break;
+ return seed_value_from_float(arg->v_float);
case GI_TYPE_TAG_DOUBLE:
- g_value_set_double(&gval,arg->v_double );
- break;
+ return seed_value_from_double(arg->v_double);
case GI_TYPE_TAG_UTF8:
- g_value_set_string(&gval,arg->v_string);
- break;
+ return seed_value_from_string(arg->v_string);
case GI_TYPE_TAG_INTERFACE:
{
GIBaseInfo *interface;
@@ -364,20 +337,17 @@
{
if (arg->v_pointer == 0)
{
- g_value_unset(&gval);
return JSValueMakeNull(eng->context);
}
- g_value_set_object(&gval, arg->v_pointer);
- break;
+ return seed_value_from_object(arg->v_pointer);
}
else if (interface_type == GI_INFO_TYPE_ENUM)
{
- g_value_set_long(&gval, arg->v_double);
- return 0;
+ return seed_value_from_double(arg->v_double);
}
- else
+ else if (interface_type == GI_INFO_TYPE_STRUCT)
{
- printf("OH NO! \n");
+ return seed_make_struct(arg->v_pointer);
}
}
@@ -385,9 +355,7 @@
return FALSE;
}
- ret = seed_value_from_gvalue(&gval);
- g_value_unset(&gval);
- return ret;
+ return 0;
}
gboolean seed_gi_supports_type(GITypeInfo * type_info)
@@ -490,13 +458,13 @@
if (type == GI_INFO_TYPE_UNION)
{
- return seed_make_union(g_value_peek_pointer(gval),
- info);
+ return seed_make_union(g_value_peek_pointer(gval));
+
}
else if (type == GI_INFO_TYPE_STRUCT)
{
- return seed_make_struct(g_value_peek_pointer(gval),
- info);
+ return seed_make_struct(g_value_peek_pointer(gval));
+
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]