seed r114 - trunk/libseed



Author: racarr
Date: Wed Nov  5 03:53:04 2008
New Revision: 114
URL: http://svn.gnome.org/viewvc/seed?rev=114&view=rev

Log:
Add Seed.closure, allows you to make GClosures to pass in to things like 
GtkAccelGroups. Make flags work.


Modified:
   trunk/libseed/seed-builtins.c
   trunk/libseed/seed-engine.c
   trunk/libseed/seed-signals.c
   trunk/libseed/seed-signals.h
   trunk/libseed/seed-types.c

Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c	(original)
+++ trunk/libseed/seed-builtins.c	Wed Nov  5 03:53:04 2008
@@ -300,6 +300,42 @@
 	return JSValueMakeBoolean(ctx, 1);
 }
 
+JSValueRef
+seed_closure(JSContextRef ctx,
+		 JSObjectRef function,
+		 JSObjectRef this_object,
+		 size_t argumentCount,
+		 const JSValueRef arguments[], JSValueRef * exception)
+{
+		GClosure * closure;
+
+		if (argumentCount < 1 || argumentCount > 2)
+		{
+				gchar * mes = g_strdup_printf("Seed.closure expected 1 or 2"
+											  "arguments, got %d",
+											  argumentCount);
+				seed_make_exception(exception, "ArgumentError", mes);
+				g_free(mes);
+				return JSValueMakeNull(ctx);
+		}
+		
+		closure = g_closure_new_simple(sizeof(SeedClosure), 0);
+		g_closure_set_marshal(closure, seed_signal_marshal_func);
+		
+		((SeedClosure *) closure)->function = (JSObjectRef) arguments[0];
+		((SeedClosure *) closure)->object =
+				0;
+		if (argumentCount == 2 && !JSValueIsNull(eng->context, arguments[1])) {
+				JSValueProtect(eng->context, (JSObjectRef) arguments[1]);
+				((SeedClosure *) closure)->this = (JSObjectRef) arguments[1];
+		} else
+				((SeedClosure *) closure)->this = 0;
+		
+		JSValueProtect(eng->context, (JSObjectRef) arguments[0]);
+		
+		return (JSValueRef)seed_make_struct(closure, 0);
+}
+
 void seed_init_builtins(int *argc, char ***argv)
 {
 	int i;
@@ -315,6 +351,7 @@
 	seed_create_function("check_syntax", &seed_check_syntax, obj);
 	seed_create_function("introspect", &seed_introspect, obj);
 	seed_create_function("fork", &seed_fork, obj);
+	seed_create_function("closure", &seed_closure, obj);
 	seed_create_function("setTimeout", &seed_set_timeout, obj);
 
 	arrayObj = JSObjectMake(eng->context, NULL, NULL);

Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c	(original)
+++ trunk/libseed/seed-engine.c	Wed Nov  5 03:53:04 2008
@@ -714,7 +714,9 @@
 		} else if (info &&
 				 (g_base_info_get_type(info) == GI_INFO_TYPE_CALLBACK))
 		{
-				JSObjectRef callback_ref = JSObjectMake(eng->context, seed_callback_class, info);
+				JSObjectRef callback_ref = JSObjectMake(eng->context, 
+														seed_callback_class, 
+														info);
 				seed_value_set_property(namespace_ref,
 										g_base_info_get_name(info),
 										(JSValueRef)callback_ref);

Modified: trunk/libseed/seed-signals.c
==============================================================================
--- trunk/libseed/seed-signals.c	(original)
+++ trunk/libseed/seed-signals.c	Wed Nov  5 03:53:04 2008
@@ -26,13 +26,6 @@
 	GObject *object;
 } signal_privates;
 
-typedef struct _SeedClosure {
-	GClosure closure;
-	JSObjectRef function;
-	JSObjectRef object;
-	JSObjectRef this;
-} SeedClosure;
-
 static void seed_add_signal_to_object(JSObjectRef object_ref,
 				      GObject * obj, GSignalQuery * signal)
 {
@@ -100,7 +93,7 @@
 	}
 }
 
-static void
+void
 seed_signal_marshal_func(GClosure * closure,
 			 GValue * return_value,
 			 guint n_param_values,

Modified: trunk/libseed/seed-signals.h
==============================================================================
--- trunk/libseed/seed-signals.h	(original)
+++ trunk/libseed/seed-signals.h	Wed Nov  5 03:53:04 2008
@@ -22,6 +22,20 @@
 
 #include "seed-private.h"
 
+typedef struct _SeedClosure {
+	GClosure closure;
+	JSObjectRef function;
+	JSObjectRef object;
+	JSObjectRef this;
+} SeedClosure;
+
+void
+seed_signal_marshal_func(GClosure * closure,
+						 GValue * return_value,
+						 guint n_param_values,
+						 const GValue * param_values,
+						 gpointer invocation_hint, gpointer marshall_data);
+
 void seed_add_signals_to_object(JSObjectRef object_ref, GObject * obj);
 JSClassDefinition *seed_get_signal_class(void);
 extern JSClassRef gobject_signal_class;

Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c	(original)
+++ trunk/libseed/seed-types.c	Wed Nov  5 03:53:04 2008
@@ -155,6 +155,8 @@
 				return G_TYPE_OBJECT;
 			else if (interface_type == GI_INFO_TYPE_ENUM)
 				return G_TYPE_LONG;
+			else if (interface_type == GI_INFO_TYPE_FLAGS)
+				return G_TYPE_LONG;
 			else if (interface_type == GI_INFO_TYPE_STRUCT)
 				return G_TYPE_POINTER;
 		}
@@ -250,7 +252,8 @@
 
 				arg->v_pointer = g_object_ref(gobject);
 				break;
-			} else if (interface_type == GI_INFO_TYPE_ENUM) {
+			} else if (interface_type == GI_INFO_TYPE_ENUM ||
+					   interface_type == GI_INFO_TYPE_FLAGS) {
 				arg->v_long = JSValueToNumber(eng->context,
 							      value, NULL);
 				break;
@@ -339,7 +342,8 @@
 					return JSValueMakeNull(eng->context);
 				}
 				return seed_value_from_object(arg->v_pointer, exception);
-			} else if (interface_type == GI_INFO_TYPE_ENUM) {
+			} else if (interface_type == GI_INFO_TYPE_ENUM ||
+					   interface_type == GI_INFO_TYPE_FLAGS) {
 				return seed_value_from_double(arg->v_double, exception);
 			} else if (interface_type == GI_INFO_TYPE_STRUCT) {
 				return seed_make_struct(arg->v_pointer,
@@ -485,7 +489,8 @@
 		return seed_make_struct(g_value_get_pointer(gval), 0);
 	}
 
-	if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_ENUM))
+	if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_ENUM) || 
+		g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_FLAGS))
 		return seed_value_from_long(gval->data[0].v_long, exception);
 	else if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_ENUM))
 		return seed_value_from_long(gval->data[0].v_long, exception);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]