[seed] Make importer work for including the JS extensions to GI modules



commit 59194331a6c2911b85c60da07e705de921631777
Author: Robert Carr <racarr mireia (none)>
Date:   Sun Apr 12 10:06:39 2009 -0400

    Make importer work for including the JS extensions to GI modules
---
 extensions/Clutter.js   |    2 ++
 extensions/GObject.js   |    2 ++
 extensions/Gio.js       |    2 ++
 extensions/Gtk.js       |    2 ++
 extensions/Makefile.am  |    2 +-
 extensions/Seed.js      |    2 +-
 libseed/seed-engine.c   |   11 +++++------
 libseed/seed-importer.c |   21 ++++++++++++++++-----
 8 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/extensions/Clutter.js b/extensions/Clutter.js
index f0c131e..e49bb75 100644
--- a/extensions/Clutter.js
+++ b/extensions/Clutter.js
@@ -1,3 +1,5 @@
+const Clutter = imports.gi.Clutter;
+
 Clutter.Actor.prototype.animate = function(mode, duration, json)
 {
 	var properties = new Array();
diff --git a/extensions/GObject.js b/extensions/GObject.js
index 81cb089..6fd4893 100644
--- a/extensions/GObject.js
+++ b/extensions/GObject.js
@@ -1,3 +1,5 @@
+const GObject = imports.gi.GObject;
+
 (function()
  {
      var types = [{name:"NONE", fundamental: 1},
diff --git a/extensions/Gio.js b/extensions/Gio.js
index bc6ffb1..5372148 100755
--- a/extensions/Gio.js
+++ b/extensions/Gio.js
@@ -1,3 +1,5 @@
+const Gio = imports.gi.Gio;
+
 (function()
 {
     var prototype = Gio.FileInputStream.prototype;
diff --git a/extensions/Gtk.js b/extensions/Gtk.js
index b30f1b1..e17f6b7 100755
--- a/extensions/Gtk.js
+++ b/extensions/Gtk.js
@@ -1,3 +1,5 @@
+const Gtk = imports.gi.Gtk;
+
 (function()
  {
 	 var pack = function(packing)
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index 6190b6f..b3ac716 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -1,4 +1,4 @@
 EXTRA_DIST= Gio.js Seed.js Gtk.js GObject.js Clutter.js
 
-extensiondir=$(datadir)/seed
+extensiondir=$(datadir)/seed/extensions
 extension_DATA = Gio.js Seed.js Gtk.js GObject.js Clutter.js
diff --git a/extensions/Seed.js b/extensions/Seed.js
index 747f549..e426e72 100755
--- a/extensions/Seed.js
+++ b/extensions/Seed.js
@@ -653,5 +653,5 @@ Seed.thread_repl = function()
 
 Seed.printf = function () { Seed.print(Seed.sprintf.apply(this, arguments)) };
 
-imports.searchPath = [".", "/usr/local/lib/seed", "/usr/lib/seed"];
+      imports.searchPath = [".", "/usr/local/lib/seed", "/usr/lib/seed", "/usr/local/share/seed", "/usr/share/seed"];
 
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 328732d..15b61b9 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -1516,9 +1516,9 @@ seed_init (gint * argc, gchar *** argv)
     JSStringCreateWithUTF8CString ("Seed.import_namespace(\""
 				   "GObject\");"
 				   "try{Seed.include(\"/usr/share/"
-				   "seed/Seed.js\");} catch(e){}"
+				   "seed/extensions/Seed.js\");} catch(e){}"
 				   "Seed.include(\"/usr/local/share"
-				   "/seed/Seed.js\");");
+				   "/seed/extensions/Seed.js\");");
   JSEvaluateScript (eng->context, defaults_script, NULL, NULL, 0, NULL);
   JSStringRelease (defaults_script);
 
@@ -1599,12 +1599,11 @@ seed_init_with_context_group (gint * argc,
   seed_gtype_init (eng);
 
   defaults_script =
-    JSStringCreateWithUTF8CString ("Seed.import_namespace(\""
-				   "GObject\");"
+    JSStringCreateWithUTF8CString ("const GObject = imports.gi.GObject;"
 				   "try{Seed.include(\"/usr/share/"
-				   "seed/Seed.js\");} catch(e){}"
+				   "seed/extensions/Seed.js\");} catch(e){}"
 				   "Seed.include(\"/usr/local/share"
-				   "/seed/Seed.js\");");
+				   "/seed/extensions/Seed.js\");");
   JSEvaluateScript (eng->context, defaults_script, NULL, NULL, 0, NULL);
   JSStringRelease (defaults_script);
 
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index 94f09b8..4d426b2 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -274,6 +274,8 @@ seed_gi_importer_do_namespace (JSContextRef ctx,
   GError *e = NULL;
   guint n, i;
   gchar *version;
+  gchar *jsextension;
+  JSStringRef extension_script;
   
   if (namespace_ref = g_hash_table_lookup (gi_imports, namespace))
     {
@@ -332,6 +334,14 @@ seed_gi_importer_do_namespace (JSContextRef ctx,
     }
   
   g_hash_table_insert (gi_imports, g_strdup(namespace), namespace_ref);
+
+  jsextension = g_strdup_printf ("imports.extensions.%s",
+				namespace);
+  extension_script = JSStringCreateWithUTF8CString (jsextension);
+  JSEvaluateScript (ctx, extension_script, NULL, NULL, 0, NULL);
+  JSStringRelease (extension_script);
+  g_free (jsextension);
+
   
   return namespace_ref;
   
@@ -493,9 +503,12 @@ seed_importer_handle_file (JSContextRef ctx,
 
   
   nctx = JSGlobalContextCreateInGroup (context_group, 0);
+  global = JSContextGetGlobalObject (nctx);
+  seed_object_set_property (ctx, global, "imports", importer);
+
   JSEvaluateScript (nctx, file_contents, NULL, file_name, 0, exception);
 
-  global = JSContextGetGlobalObject (nctx);
+
   g_hash_table_insert (file_imports, file_path, global);
   
   JSGlobalContextRelease ((JSGlobalContextRef) nctx);
@@ -527,12 +540,10 @@ seed_importer_search (JSContextRef ctx,
       dir = g_dir_open ((gchar *)walk->data, 0, &e);
       if (e)
 	{
-	  seed_make_exception_from_gerror (ctx, exception, e);
 	  g_error_free (e);
-	  g_free (prop_as_lib);
-	  seed_importer_free_search_path (path);
 	  
-	  return NULL;
+	  walk = walk->next;
+	  continue;
 	}
       while (entry = g_dir_read_name(dir))
 	{



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