コード例 #1
0
        private void InitEngine(ZipFile z)
        {
            _engine.Execute(Resources.query);
            _engine.Execute(Resources.Module);

            _engine.Add("RessourceReader", typeof(RessourceReader));
            _engine.Add("host", new ExtendedHostFunctions());

            _engine.Execute("$['res'] = function(plugin, name) {return new RessourceReader(plugin).Read(name);}");

            // add function to script engine to control the properties
            _engine.Add <Delegate>("property", new StaticMethodFunc(args =>
            {
                if (args.Length == 1)
                {
                    return(Properties.Get(args[0].ToString()));
                }
                else if (args.Length == 2)
                {
                    Properties.Set(args[0].ToString(), args[1]);

                    return(null);
                }

                return(null);
            }));

            /*_engine.Add("require", new Action<string>(_ =>
             * {
             *  var i = new StreamReader(z[_].OpenReader());
             *
             *  _engine.Execute(i.ReadToEnd());
             * }));*/

            _engine.Add("import", new Action <string>(_ =>
            {
                var l = Library.Load(_);
                l.Apply(_engine);

                Dependencies.Add(l);
            }));

            _engine.AddHostObject("globals", HostItemFlags.GlobalMembers, new Globals(this));

            _engine.Add("math", new OpenIDE.Library.Math());
            _engine.Add("JSON", new OpenIDE.Library.JSON());
            _engine.Add("XmlHttpRequest", typeof(XmlHttpRequest));
            _engine.Add("console", new OpenIDE.Library.Console.FirebugConsole());

            _engine.Add("register_window", new Action <string, Window>((n, w) => Windows.Add(n, w)));

            _engine.Add("debug", Workspace.Output);

            Events.Fire("OnReady");
        }
コード例 #2
0
ファイル: Plugin.cs プロジェクト: jwoff78/OpenIDE
        private void InitEngine(ZipFile z)
        {
            _engine.Add("host", new ExtendedHostFunctions());

            // add function to script engine to control the properties
            _engine.Add <Delegate>("property", new StaticMethodFunc(args =>
            {
                if (args.Length == 1)
                {
                    return(Properties.Get(args[0].ToString()));
                }
                else if (args.Length == 2)
                {
                    Properties.Set(args[0].ToString(), args[1]);

                    return(null);
                }

                return(null);
            }));
            _engine.Add("require", new Action <string>(_ =>
            {
                var i = new StreamReader(z[_].OpenReader());

                _engine.Execute(i.ReadToEnd());
            }));
            _engine.Add("import", new Action <string>(_ =>
            {
                var l = Library.Load(_);
                l.Apply(_engine, Language);

                Dependencies.Add(l);
            }));

            _engine.Add("math", new OpenIDE.Library.Math());
            _engine.Add("JSON", new OpenIDE.Library.JSON());
            _engine.Add("XmlHttpRequest", typeof(OpenIDE.Library.XmlHttpRequest));
            _engine.Add("console", new OpenIDE.Library.Console.FirebugConsole());

            _engine.Add("argb", new Func <int, int, int, int, Color>((r, g, b, a) =>
            {
                return(OpenIDE.Library.Functions.Argb(r, g, b, a));
            }));
            _engine.Add("hsla", new Func <double, double, double, int, Color>((h, s, l, a) =>
            {
                return(OpenIDE.Library.Functions.Hsla(h, s, l, a));
            }));
            _engine.Add("hexadecimal", new Func <string, Color>(_ =>
            {
                return(OpenIDE.Library.Functions.Hexadecimal(_));
            }));
            _engine.Add("register_window", new Action <string, Window>((n, w) => Windows.Add(n, w)));
            _engine.Add("notify", new Action <string, string>((title, content) =>
                                                              NotificationService.Notify(title, content)));
            _engine.Add("prompt", new Func <string, string, string>((_, __) =>
            {
                return(Prompt.Show(_, __));
            }));
            _engine.Add("debug", Workspace.Output);

            _engine.Add("plugin", this);

            Events.Fire("OnReady");
        }