seed r149 - trunk/libseed



Author: racarr
Date: Fri Nov  7 03:52:59 2008
New Revision: 149
URL: http://svn.gnome.org/viewvc/seed?rev=149&view=rev

Log:
Rework GObject subclassing. Now looks like.
HelloWindow = new GType({parent: Gtk.Window, name: "HelloWindow"}). 
Still need to do instance/class initialization.


Added:
   trunk/libseed/seed-gtype.c
   trunk/libseed/seed-gtype.h
Modified:
   trunk/libseed/Makefile.am
   trunk/libseed/Makefile.in
   trunk/libseed/seed-builtins.c
   trunk/libseed/seed-engine.c
   trunk/libseed/seed-private.h

Modified: trunk/libseed/Makefile.am
==============================================================================
--- trunk/libseed/Makefile.am	(original)
+++ trunk/libseed/Makefile.am	Fri Nov  7 03:52:59 2008
@@ -13,6 +13,8 @@
 	seed-signals.c \
 	seed-signals.h \
 	seed-structs.c \
+	seed-gtype.c \
+	seed-gtype.h \
 	seed-structs.h \
 	seed-types.c \
 	seed-types.h

Modified: trunk/libseed/Makefile.in
==============================================================================
--- trunk/libseed/Makefile.in	(original)
+++ trunk/libseed/Makefile.in	Fri Nov  7 03:52:59 2008
@@ -55,7 +55,8 @@
 am__DEPENDENCIES_1 =
 libseed_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
 am_libseed_la_OBJECTS = seed-closure.lo seed-builtins.lo \
-	seed-engine.lo seed-signals.lo seed-structs.lo seed-types.lo
+	seed-engine.lo seed-signals.lo seed-structs.lo seed-gtype.lo \
+	seed-types.lo
 libseed_la_OBJECTS = $(am_libseed_la_OBJECTS)
 DEFAULT_INCLUDES = -I  am__isrc@ -I$(top_builddir)
 depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -246,6 +247,8 @@
 	seed-signals.c \
 	seed-signals.h \
 	seed-structs.c \
+	seed-gtype.c \
+	seed-gtype.h \
 	seed-structs.h \
 	seed-types.c \
 	seed-types.h
@@ -337,6 +340,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/seed-builtins Plo am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/seed-closure Plo am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/seed-engine Plo am__quote@
+ AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/seed-gtype Plo am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/seed-signals Plo am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/seed-structs Plo am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/seed-types Plo am__quote@

Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c	(original)
+++ trunk/libseed/seed-builtins.c	Fri Nov  7 03:52:59 2008
@@ -395,76 +395,6 @@
 		return JSObjectMake(eng->context, seed_native_callback_class, privates);
 }
 
-JSValueRef 
-seed_define_gtype(JSContextRef ctx,
-		 JSObjectRef function,
-		 JSObjectRef this_object,
-		 size_t argumentCount,
-		 const JSValueRef arguments[], JSValueRef * exception)
-{
-	GType parent_type, instance_type;
-	GType *parent_interfaces;
-	guint n_parent_interfaces;
-	gint i;
-	GTypeQuery query;
-	gpointer gclass;
-	GTypeInfo type_info  = {
-		0,
-		(GBaseInitFunc) NULL,
-		(GBaseFinalizeFunc) NULL,
-		(GClassInitFunc) NULL,
-		(GClassFinalizeFunc) NULL,
-		NULL,
-		0,
-		0,
-		(GInstanceInitFunc) NULL
-	};
-	gchar * new_type_name;
-	
-	if (argumentCount != 3)
-	{
-			gchar * mes = g_strdup_printf("Seed.define_gtype expected 3"
-										  " arguments, got %d",
-										  argumentCount);
-			seed_make_exception(exception, "ArgumentError", mes);
-			g_free(mes);
-			return JSValueMakeNull(eng->context);
-	}
-	
-	if (!JSValueIsObjectOfClass(eng->context, 
-								arguments[0], 
-								gobject_constructor_class))
-	{
-					seed_make_exception(exception, "ArgumentError",
-										"Seed.define_gtype expected"
-										" GObject type as first argument");
-					return JSValueMakeNull(eng->context);
-	}
-	parent_type = (GType)JSObjectGetPrivate((JSObjectRef)arguments[0]);
-	
-	parent_interfaces = g_type_interfaces(parent_type, &n_parent_interfaces);
-	new_type_name = seed_value_to_string(arguments[1], exception);
-	
-	type_info.class_data = (gpointer)arguments[2];
-	
-	g_type_query(parent_type, &query);
-	type_info.class_size = query.class_size;
-	type_info.instance_size = query.instance_size;
-	
-	instance_type = g_type_register_static(parent_type,
-										   new_type_name,
-										   &type_info, 0);
-	printf("Type name: %s \n", g_type_name(instance_type));
-	
-	seed_gobject_get_class_for_gtype(instance_type);
-	
-	return JSObjectMake(eng->context, 
-						gobject_constructor_class, 
-						(gpointer)instance_type);
-}
-	
-	
-
 void seed_init_builtins(gint *argc, gchar ***argv)
 {
 	guint i;
@@ -483,8 +413,6 @@
 	seed_create_function("closure", &seed_closure, obj);
 	seed_create_function("setTimeout", &seed_set_timeout, obj);
 	seed_create_function("closure_native", &seed_closure_native, obj);
-	seed_create_function("define_gtype", &seed_define_gtype, obj);
-
 
 	arrayObj = JSObjectMake(eng->context, NULL, NULL);
 

Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c	(original)
+++ trunk/libseed/seed-engine.c	Fri Nov  7 03:52:59 2008
@@ -859,43 +859,46 @@
 
 gboolean seed_init(gint *argc, gchar ***argv)
 {
-	JSObjectRef seed_obj_ref;
-	JSStringRef defaults_script;
+		JSObjectRef seed_obj_ref;
+		JSStringRef defaults_script;
 
-	g_type_init();
-	g_log_set_handler("GLib-GObject", G_LOG_LEVEL_WARNING, seed_log_handler,
-			  0);
-
-	qname = g_quark_from_static_string("js-type");
-	qprototype = g_quark_from_static_string("js-prototype");
-
-	eng = (SeedEngine *) g_malloc(sizeof(SeedEngine));
-
-	eng->context = JSGlobalContextCreateInGroup(NULL, NULL);
-	eng->global = JSContextGetGlobalObject(eng->context);
-	gobject_class = JSClassCreate(&gobject_def);
-	JSClassRetain(gobject_class);
-	gobject_method_class = JSClassCreate(&gobject_method_def);
-	JSClassRetain(gobject_method_class);
-	gobject_constructor_class = JSClassCreate(&gobject_constructor_def);
-	JSClassRetain(gobject_constructor_class);
-	gobject_signal_class = JSClassCreate(seed_get_signal_class());
-	JSClassRetain(gobject_signal_class);
-	seed_callback_class = JSClassCreate(&seed_callback_def);
-	JSClassRetain(seed_callback_class);
-
-	g_type_set_qdata(G_TYPE_OBJECT, qname, gobject_class);
-
-	seed_obj_ref = JSObjectMake(eng->context, NULL, NULL);
-	seed_value_set_property(eng->global, "Seed", seed_obj_ref);
-	JSValueProtect(eng->context, seed_obj_ref);
-
-	seed_create_function("import_namespace", &seed_gi_import_namespace,
-			     seed_obj_ref);
-	seed_init_builtins(argc, argv);
-	seed_closures_init();
+		g_type_init();
+		g_log_set_handler("GLib-GObject", G_LOG_LEVEL_WARNING, seed_log_handler,
+						  0);
+		
+		qname = g_quark_from_static_string("js-type");
+		qprototype = g_quark_from_static_string("js-prototype");
+		
+		eng = (SeedEngine *) g_malloc(sizeof(SeedEngine));
+		
+		eng->context = JSGlobalContextCreateInGroup(NULL, NULL);
+		eng->global = JSContextGetGlobalObject(eng->context);
+		gobject_class = JSClassCreate(&gobject_def);
+		JSClassRetain(gobject_class);
+		gobject_method_class = JSClassCreate(&gobject_method_def);
+		JSClassRetain(gobject_method_class);
+		gobject_constructor_class = JSClassCreate(&gobject_constructor_def);
+		JSClassRetain(gobject_constructor_class);
+		gobject_signal_class = JSClassCreate(seed_get_signal_class());
+		JSClassRetain(gobject_signal_class);
+		seed_callback_class = JSClassCreate(&seed_callback_def);
+		JSClassRetain(seed_callback_class);
+		
+		g_type_set_qdata(G_TYPE_OBJECT, qname, gobject_class);
+		
+		seed_obj_ref = JSObjectMake(eng->context, NULL, NULL);
+		seed_value_set_property(eng->global, "Seed", seed_obj_ref);
+		JSValueProtect(eng->context, seed_obj_ref);
+		
+		seed_create_function("import_namespace", &seed_gi_import_namespace,
+							 seed_obj_ref);
+		seed_init_builtins(argc, argv);
+		seed_closures_init();
+		
+		seed_gtype_init();
 
-	defaults_script =
+
+		defaults_script =
 	    JSStringCreateWithUTF8CString("Seed.include(\"/usr/local/share"
 					  "/seed/Seed.js\")");
 	JSEvaluateScript(eng->context, defaults_script, NULL, NULL, 0, NULL);

Added: trunk/libseed/seed-gtype.c
==============================================================================
--- (empty file)
+++ trunk/libseed/seed-gtype.c	Fri Nov  7 03:52:59 2008
@@ -0,0 +1,111 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * seed-gtype.c
+ * Copyright (C) Robert Carr 2008 <carrr rpi edu>
+ *
+ * libseed is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libseed is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "seed-private.h"
+
+JSClassRef seed_gtype_class;
+
+static JSObjectRef seed_gtype_constructor_invoked(JSContextRef ctx,
+												  JSObjectRef constructor,
+												  size_t argumentCount,
+												  const JSValueRef arguments[],
+												  JSValueRef * exception)
+{
+		JSValueRef class_init, instance_init, name, parent_ref;
+		GType parent_type, new_type;
+		gchar * new_name;
+		GTypeInfo type_info = {
+				0,
+				(GBaseInitFunc) NULL,
+				(GBaseFinalizeFunc) NULL,
+				(GClassInitFunc) NULL,
+				(GClassFinalizeFunc) NULL,
+				NULL,
+				0,
+				0,
+				NULL
+		};
+				
+		GTypeQuery query;
+
+		if (argumentCount != 1)
+		{
+				gchar * mes = g_strdup_printf("GType constructor expected 1 "
+											  "argument, got %d \n", 
+											  argumentCount);
+				seed_make_exception(exception, "ArgumentError", mes);
+				g_free(mes);
+				return (JSObjectRef)JSValueMakeNull(eng->context);
+ 		}
+		if (!JSValueIsObject(eng->context, arguments[0]))
+		{
+				seed_make_exception(exception, "ArgumentError",
+									"GType constructor expected a"
+									"class definition object. Got a nonobject");
+		}
+		parent_ref = seed_value_get_property(arguments[0], "parent");
+		class_init = seed_value_get_property(arguments[0], "class_init");
+		instance_init = seed_value_get_property(arguments[0], "instance_init");
+		name = seed_value_get_property(arguments[0], "name");
+		
+		new_name = seed_value_to_string(name, exception);
+		if (!JSValueIsObjectOfClass(eng->context, 
+									parent_ref,
+									gobject_constructor_class))
+		{
+				seed_make_exception(exception, "TypeError",
+									"GType constructor expected"
+									" GObject type for parent");
+		}
+		parent_type = (GType)JSObjectGetPrivate((JSObjectRef)parent_ref);
+		
+		
+		g_type_query(parent_type, &query);
+		type_info.class_size = query.class_size;
+		type_info.instance_size = query.instance_size;
+		
+		new_type = g_type_register_static(parent_type,
+										  new_name,
+										  &type_info, 0);
+		seed_gobject_get_class_for_gtype(new_type);
+		printf("Type_name: %s \n", g_type_name(new_type));
+		
+		
+		g_free(new_name);
+		return JSObjectMake(eng->context, gobject_constructor_class, 
+							(gpointer)new_type);
+}
+
+void seed_gtype_init(void)
+{
+		JSClassDefinition def = kJSClassDefinitionEmpty;
+		JSObjectRef gtype_constructor;
+
+		def.callAsConstructor = seed_gtype_constructor_invoked;
+		seed_gtype_class = JSClassCreate(&def);
+		JSClassRetain(seed_gtype_class);
+		
+		gtype_constructor = JSObjectMake(eng->context, seed_gtype_class, 0);
+		
+		seed_value_set_property(eng->global, "GType", gtype_constructor);
+		
+}
+
+
+

Added: trunk/libseed/seed-gtype.h
==============================================================================
--- (empty file)
+++ trunk/libseed/seed-gtype.h	Fri Nov  7 03:52:59 2008
@@ -0,0 +1,27 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * seed-gtype.h
+ * Copyright (C) Robert Carr 2008 <carrr rpi edu>
+ *
+ * libseed is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libseed is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _SEED_GTYPE_H
+#define _SEED_GTYPE_H
+
+#include "seed-private.h"
+
+void seed_gtype_init(void);
+
+#endif

Modified: trunk/libseed/seed-private.h
==============================================================================
--- trunk/libseed/seed-private.h	(original)
+++ trunk/libseed/seed-private.h	Fri Nov  7 03:52:59 2008
@@ -42,6 +42,7 @@
 #include "seed-builtins.h"
 #include "seed-structs.h"
 #include "seed-closure.h"
+#include "seed-gtype.h"
 
 
 #endif



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