//----------------------------------------------------------------------------------------------
    public static IntPtr CreateScope()
    {
        // まだエンジンが作られていなければ
        if (runspace == null)
        {
            try
            {
                // create Powershell runspace
                runspace = RunspaceFactory.CreateRunspace();

                // open it
                runspace.Open();


                hm = new Hidemaru();
                runspace.SessionStateProxy.SetVariable("hm", hm);
                runspace.SessionStateProxy.SetVariable("AssemblyPath", new List <String>());
                dpr = new DllPathResolver();

                // ダミー関数の定義
                DoString("function DestroyScope() {}");

                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message + "生成時エラー");
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
        public static void Main()
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            using (engine = new V8ScriptEngine(typeof(ClearScriptConsole).Name, V8ScriptEngineFlags.EnableDebugging))
            {
                engine.AddHostObject("host", new ExtendedHostFunctions());
                engine.AddHostObject("clr", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib", "System", "System.Core", "ClearScript"));

                hm = new Hidemaru();
                engine.AddHostType("hm", typeof(Hidemaru));
                console = new hmV8Console();
                engine.AddHostType("console", typeof(hmV8Console));

                engine.AllowReflection = true;

                // 特別にR関数を追加
                String expression = @"
                function R(text){
                    return text.toString().split(""\n"").slice(1,-1).join(""\n"");
                }
                ";
                engine.Execute(expression);


                RunStartupFile(engine);
                RunConsole(engine);
            }

            AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
        }
Beispiel #3
0
    public static IntPtr CreateScope()
    {
        // まだエンジンが作られていなければ
        if (l == null || g == null)
        {
            try
            {
                //エンジン作成
                l = new Lua();
                g = l.CreateEnvironment();

                hm = new Hidemaru();
                g.RegisterPackage("hm", typeof(Hidemaru));
                dpr = new DllPathResolver();
                // アセンブリのローダのショートカット
                g["load_assembly"] = new Func <String, Assembly>(asmname => System.Reflection.Assembly.Load(asmname));

                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message);
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
    //----------------------------------------------------------------------------------------------
    public static IntPtr CreateScope()
    {
        // まだエンジンが作られていなければ
        if (pe == null || ss == null)
        {
            try
            {
                //エンジン作成
                pe = Python.CreateEngine();
                ss = pe.CreateScope();
                hm = new Hidemaru();
                ss.SetVariable("hm", hm);

                // マクロのパスを足す
                SetCurrentMacroDirectory();

                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message);
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
Beispiel #5
0
        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            try
            {
                var requestingAssembly = args.RequestingAssembly;
                var requestedAssembly  = new AssemblyName(args.Name);

                // ①カレントディレクトリの.dllのファイル名部分だけを指定している場合(.NETの既存ライブラリと同じ書き方。
                // もしくは、C#のusingで読み込めなかった場合もこれに該当する
                String currentmacrodirectory = (String)Hidemaru.Macro.Var["currentmacrodirectory"];
                var    targetfullpath        = currentmacrodirectory + @"\" + requestedAssembly.Name + ".dll";
                if (System.IO.File.Exists(targetfullpath))
                {
                    return(Assembly.LoadFile(targetfullpath));
                }

                // ②そのようなフルパスが指定されている場合(フルパスを指定した書き方)
                targetfullpath = requestedAssembly.Name;
                if (System.IO.File.Exists(targetfullpath))
                {
                    // そのファイルのディレクトリ
                    var normalizedfullpath = System.IO.Path.GetFullPath(targetfullpath);
                    var targetdirectory    = System.IO.Path.GetDirectoryName(normalizedfullpath);

                    return(Assembly.LoadFile(targetfullpath));
                }

                // ③パスが特別に登録されている
                // 何型かはわからないが… 呼び出し側は list[x]形式で呼び出せるものだと考えた。
                LuaResult r        = g.DoChunk("return package.path", "test.lua");
                String    asm_path = r.ToString();

                if (asm_path != null)
                {
                    foreach (var dir in asm_path.Split(';'))
                    {
                        targetfullpath = dir + @"\" + requestedAssembly.Name + ".dll";
                        Hidemaru.debuginfo(targetfullpath);
                        if (System.IO.File.Exists(targetfullpath))
                        {
                            return(Assembly.LoadFile(targetfullpath));
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return(null);
        }
    public static String OnCustomTranslateHTML(string filename)
    {
        String rawtext = Hidemaru.Edit.TotalText;

        if (engine.Script["OnCustomTranslateHTML"] != null)
        {
            try
            {
                String htmltext = engine.Script.OnCustomTranslateHTML(filename, rawtext);
                return(htmltext);
            }
            catch (Exception e) {
                Hidemaru.debuginfo(e.Message);
            }
        }
        return(rawtext);
    }
 public static void assert(Object assert_exp, params Object[] expressions)
 {
     // 最初が「JavaScript解釈で」False
     if (engine.Script.Boolean(assert_exp) == false)
     {
         if (expressions.Length > 0)
         {
             object[] formattedItems1 = FormatObjects(expressions);
             object[] formattedItems2 = new object[formattedItems1.Length + 1];
             formattedItems2[0] = "Assertion failed:";
             Array.Copy(formattedItems1, 0, formattedItems2, 1, formattedItems1.Length);
             Hidemaru.debuginfo(formattedItems2);
         }
         else
         {
             assert();
         }
     }
 }
    public static IntPtr CreateScope()
    {
        // まだエンジンが作られていなければ
        if (re == null || ss == null)
        {
            try
            {
                //エンジン作成
                re = IronRuby.Ruby.CreateEngine(opt => { opt.ExceptionDetail = true; });
                ss = re.CreateScope();

                hm = new Hidemaru();
                ss.SetVariable("hm" + tmp, hm);

                String code =
                    "$hm = self.hm" + tmp + "\n" +
                    "def DestroyScope() end\n";

                // 8.66以上の時は、自分自身をロードしたマクロファイルのディレクトリを$LOAD_PATHに追加しておく。
                // マネージの.dllが簡単にロード出来るように。
                // hmPyのようなICollectionを使うやり方だとIronRubyは上手くいかない。
                if (hm.version >= 866)
                {
                    code += "$LOAD_PATH.push($hm.Macro.Var['currentmacrodirectory'].to_s);\n";
                }

                ScriptSource source = re.CreateScriptSourceFromString(code);
                source.Execute(ss);

                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message);
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
Beispiel #9
0
    //----------------------------------------------------------------------------------------------
    public static IntPtr CreateScope()
    {
        // まだエンジンが作られていなければ
        if (engine == null)
        {
            try
            {
                // Standardモードのコンプライアンスまで引き上げる
                engine = new Microsoft.ClearScript.Windows.JScriptEngine(Microsoft.ClearScript.Windows.WindowsScriptEngineFlags.EnableStandardsMode | Microsoft.ClearScript.Windows.WindowsScriptEngineFlags.EnableDebugging);
                engine.AddHostObject("clr", new HostTypeCollection("mscorlib", "System", "System.Core"));
                engine.AddHostObject("host", new ExtendedHostFunctions());
                engine.AddHostObject("AssemblyPath", new List <String>());

                hm = new Hidemaru();
                engine.AddHostType("hm", typeof(Hidemaru));
                console = new hmJSConsole();
                engine.AddHostType("console", typeof(hmJSConsole));

                // ヒアドキュメント用の関数 R(text)
                String expression = @"
                function R(text){
                    return text.toString().match(/\/\*([\s\S]*)\*\//)[1].toString();
                }
                ";
                engine.Execute(expression);

                dpr = new DllPathResolver();

                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message);
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
Beispiel #10
0
    //----------------------------------------------------------------------------------------------
    public static IntPtr AttachScope()
    {
        // まだエンジンが作られていなければ
        if (engine == null)
        {
            try
            {
                // Standardモードのコンプライアンスまで引き上げる
                engine = new Object();

                hm = new Hidemaru();

                dpr = new DllPathResolver();

                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message);
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
Beispiel #11
0
    //----------------------------------------------------------------------------------------------
    public static IntPtr CreateScope()
    {
        // まだエンジンが作られていなければ
        if (engine == null)
        {
            try
            {
                core   = CreateCore();
                engine = core.Engine;
                core.ExposeGlobalRequire(); // requireが使えるように

                // 秀丸クラスの登録
                hm = new Hidemaru();
                engine.AddHostType("hm", typeof(Hidemaru));

                // consoleの簡易版
                console = new hmV8Console();
                engine.AddHostType("console", typeof(hmV8Console));

                // ①ヒアドキュメント用の関数
                // ②:空のDestory関数
                String expression = @"
                function R(text){
                    return text.toString().match(/\/\*([\s\S]*)\*\//)[1].toString();
                }

                hm.Macro.Var = new Proxy(()=>{}, {
                    apply: function(target, that, args) {
                        if (args.length > 1 ) {
                            return hm.Macro.__Var(args[0], args[1]);
                        }
                        else if (args.length == 1 ) {
                            return hm.Macro.__Var(args[0]);
                        }
                    },
                    get(target, prop, receiver) {
                        return hm.Macro.__Var(prop);
                    },
                    set(target, prop, val, receiver) {
                        return hm.Macro.__Var(prop, val);
                    }
                }
                )
                ";

                engine.Execute(expression);

                engine.Script.DestroyScope = new Action(() => { });

                dpr = new DllPathResolver();
                engine.AddHostObject("AssemblyPath", new List <String>());

                // ヒアドキュメント用の関数 R(text)
                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message);
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
 public static String assert()
 {
     return(Hidemaru.debuginfo("Assertion failed: console.assert"));
 }
 public static String warn(params Object[] expressions)
 {
     return(Hidemaru.debuginfo(expressions));
 }
 public static String trace(params Object[] expressions)
 {
     return(Hidemaru.debuginfo(FormatObjects(expressions)));
 }
 public static String clear(params Object[] expressions)
 {
     return(Hidemaru.debuginfo("\n\n"));
 }
 public static void clear(params Object[] expressions)
 {
     Hidemaru.debuginfo("\n\n");
 }
 public static void assert()
 {
     Hidemaru.debuginfo("Assertion failed: console.assert");
 }
 public static void warn(params Object[] expressions)
 {
     Hidemaru.debuginfo(expressions);
 }
 public static void trace(params Object[] expressions)
 {
     Hidemaru.debuginfo(FormatObjects(expressions));
 }