[seed] [libseed] Expose path to script as __script_path__ on all JS contexts



commit 43bbb4efb5929f31a8388ccfc21bebbd71996450
Author: Tim Horton <hortont svn gnome org>
Date:   Tue Jul 14 16:57:04 2009 -0400

    [libseed] Expose path to script as __script_path__ on all JS contexts

 extensions/Seed.js.in   |    6 +++---
 libseed/seed-importer.c |    6 ++++++
 2 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/extensions/Seed.js.in b/extensions/Seed.js.in
index fce2bb5..e8b4584 100644
--- a/extensions/Seed.js.in
+++ b/extensions/Seed.js.in
@@ -181,10 +181,10 @@ if(!imports.searchPath || (imports.searchPath.length == 0))
 
 	if(Seed.argv.length > 1)
 	{
-		var script_path = imports.gi.GLib.path_get_dirname(Seed.argv[1]);
+		__script_path__ = imports.gi.GLib.path_get_dirname(Seed.argv[1]);
 		
-		if(script_path && script_path != "")
-			imports.searchPath.push(script_path);
+		if(__script_path__ && __script_path__ != "")
+			imports.searchPath.push(__script_path__);
 	}
 
 	imports.searchPath.push(".");
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index fbb570d..d33e82d 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -592,6 +592,7 @@ seed_importer_handle_file (JSContextRef ctx,
 			   JSValueRef *exception)
 {
   JSContextRef nctx;
+  JSValueRef js_file_dirname;
   JSObjectRef global, c_global;
   JSStringRef file_contents, file_name;
   gchar *contents, *walk, *file_path, *canonical;
@@ -639,6 +640,11 @@ seed_importer_handle_file (JSContextRef ctx,
   global = JSContextGetGlobalObject (nctx);
   c_global = JSContextGetGlobalObject (ctx);
   JSValueProtect (eng->context, global);
+  
+  js_file_dirname = seed_value_from_string(ctx, g_path_get_dirname(file_path),
+                                           NULL);
+  
+  seed_object_set_property(nctx, global, "__script_path__", js_file_dirname);
 
   g_hash_table_insert (file_imports, canonical, global);
   g_free (file_path);



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