[seed] [libseed] Implement __init__.js functionality. When an importer directory is loaded (say imports.lig



commit acdf1ac0bdb852be8da7b947a32090ca8f1f89d0
Author: Robert Carr <racarr svn gnome org>
Date:   Sun Jul 26 12:03:11 2009 -0400

    [libseed] Implement __init__.js functionality. When an importer directory is loaded (say imports.lightsoff) if the folder contains __init__.js it will be run (with the imports.lightsoff object as this)

 libseed/seed-api.c      |    9 +++++++++
 libseed/seed-engine.h   |   11 +++++++++++
 libseed/seed-importer.c |    5 +++++
 libseed/seed.h          |    1 +
 4 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/libseed/seed-api.c b/libseed/seed-api.c
index b8a7e91..0a43326 100644
--- a/libseed/seed-api.c
+++ b/libseed/seed-api.c
@@ -405,6 +405,15 @@ seed_string_unref (JSStringRef string)
   JSStringRelease (string);
 }
 
+void 
+seed_script_destroy (SeedScript *s)
+{
+  seed_string_unref (s->script);
+  seed_string_unref (s->source_url);
+  
+  g_free (s);
+}
+
 // TODO:FIXME: Do we have an external typedef or anything for JSClassDefinition?
 
 /**
diff --git a/libseed/seed-engine.h b/libseed/seed-engine.h
index 75dd87d..904b120 100644
--- a/libseed/seed-engine.h
+++ b/libseed/seed-engine.h
@@ -68,4 +68,15 @@ typedef JSObjectRef (*SeedModuleInitCallback) (SeedEngine * eng);
 
 void seed_prepare_global_context (JSContextRef ctx);
 
+SeedScript *seed_make_script (JSContextRef ctx,
+			      const gchar * js,
+			      const gchar * source_url,
+			      gint line_number);
+SeedScript *seed_script_new_from_file (JSContextRef ctx, gchar * file);
+JSValueRef seed_script_exception (SeedScript * s);
+
+JSValueRef seed_evaluate (JSContextRef ctx, SeedScript *script, JSObjectRef this);
+
+void seed_script_destroy (SeedScript *s);
+
 #endif
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index 0ae2043..1d791ac 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -495,7 +495,12 @@ seed_make_importer_dir (JSContextRef ctx, gchar *path)
   init = g_strconcat (path, "/__init__.js", NULL);
   if (g_file_test (init, G_FILE_TEST_IS_REGULAR))
     {
+      SeedScript *s;
       SEED_NOTE (IMPORTER, "Found __init__.js (%s)", path);
+      
+      s = seed_script_new_from_file (ctx, init);
+      seed_evaluate (ctx, s, dir);
+      seed_script_destroy (s);
     }
 
   g_free (init);
diff --git a/libseed/seed.h b/libseed/seed.h
index e49190f..7fe9d31 100644
--- a/libseed/seed.h
+++ b/libseed/seed.h
@@ -88,6 +88,7 @@ SeedScript *seed_make_script (SeedContext ctx,
 			      gint line_number);
 SeedScript *seed_script_new_from_file (SeedContext ctx, gchar * file);
 SeedException seed_script_exception (SeedScript * s);
+void seed_script_destroy (SeedScript *s);
 void seed_make_exception (SeedContext ctx, SeedException exception,
 			  const gchar * name, const gchar * message, ...) G_GNUC_PRINTF (4,5);
 gchar *seed_exception_get_name (SeedContext ctx, SeedException exception);



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