Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
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);
    }