Yappo::Hatena::Group::Subtech このページをアンテナに追加 RSSフィード

 | 

2006-07-19

Eject 4 Ajaja 23:50 Eject 4 Ajaja - Yappo::Hatena::Group::Subtech を含むブックマーク はてなブックマーク - Eject 4 Ajaja - Yappo::Hatena::Group::Subtech

なんかAcme.Ejectにするとeval(name);とかでエラーがでた。

http://tech.yappo.jp/download/Ajaja-Acme_Eject.tar.gz

use('lib', '/tmp');
use('Acme_Eject');
Acme_Eject.eject();

Ajaja use lib 22:43 Ajaja use lib - Yappo::Hatena::Group::Subtech を含むブックマーク はてなブックマーク - Ajaja use lib - Yappo::Hatena::Group::Subtech

あいかわらずいじり過ぎ

$ ssjs test.js 
Hello! Ajaja!

test.js

use('lib', '/tmp');
use('Test');
Test.print('Hello! Ajaja!');

/tmp/Test.js

var Test = function () { };
Test.VERSION = 0.01;
Test.print = function(word){ print(word); };

lib.js

var lib = {};
lib.VERSION = 0.01;
lib.import = function(){
   for(var i = 0;i < arguments.length;i++) {
        ISA.push(arguments[i]);
   }
};

http://tech.yappo.jp/download/init.js.diff

--- init.js.orig        2006-07-19 22:38:36.000000000 +0900
+++ init.js     2006-07-19 22:38:39.000000000 +0900
@@ -40,29 +40,54 @@
        return eval(name);
     }
 
-    var dir = Core.JSPATH;
     var found = false;
     var file = null;
 
-    try {
-       file = dir + '/' + name.replace(/\./g, '/') + '.js';
-       Core.loadScript.call(null, file);
-       found = true;
-    } catch (e) {
-        if (e.name != 'Error')
-           throw e;
-    }
-
-    if (!found) {
+    for (var isa_count = 0;isa_count < ISA.length;isa_count++) {
+       var dir = ISA[isa_count];
        try {
-           file = dir + '/' + name.replace(/\./g, '/') + '.so';
-           var init = "JS_InitModule_" + name.replace(/\./g, '_');
-           Core.loadModule.call(null, file, init);
+           file = dir + '/' + name.replace(/\./g, '/') + '.js';
+           Core.loadScript.call(null, file);
            found = true;
        } catch (e) {
-           if (e.name != 'Error')
+            if (e.name != 'Error')
                throw e;
        }
+
+       if (!found) {
+           try {
+               file = dir + '/' + name.replace(/\./g, '/') + '.so';
+               var init = "JS_InitModule_" + name.replace(/\./g, '_');
+               Core.loadModule.call(null, file, init);
+               found = true;
+           } catch (e) {
+               if (e.name != 'Error')
+                   throw e;
+           }
+       }
+
+       if (!found)
+           continue;
+
+       // import
+       var args = new Array;
+       if (arguments.length > 1) {
+           for (var i = 1;i < arguments.length;i++) {
+               args.push(arguments[i]);
+           }
+       }
+       try {
+               if (args.length) {
+                   eval(name + '.import(args);');
+               } else {
+                   eval(name + '.import();');
+               }
+       } catch (e) {
+           if (e.name != 'Error' && e.name != 'TypeError')
+               throw e;
+       }
+
+       break;
     }
 
     if (!found)
@@ -73,3 +98,5 @@
 
     return eval(name);
 }
+
+var ISA = new Array(Core.JSPATH);
 |