CreateScope() public method

public CreateScope ( ) : ScriptScope
return ScriptScope
コード例 #1
0
ファイル: launcher.cs プロジェクト: numerodix/nametrans
    static void Main(string[] args)
    {
        // set path for dynamic assembly loading
        AppDomain.CurrentDomain.AssemblyResolve +=
            new ResolveEventHandler(ResolveAssembly);

        string path = System.IO.Path.Combine(exe_path, py_path);
        pyscript = System.IO.Path.Combine(path, pyscript);
        pyscript = System.IO.Path.GetFullPath(pyscript); // normalize

        // get runtime
        ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup();

        LanguageSetup language = Python.CreateLanguageSetup(null);
        language.Options["Debug"] = true;
        scriptRuntimeSetup.LanguageSetups.Add(language);

        ScriptRuntime runtime = new Microsoft.Scripting.Hosting.ScriptRuntime(scriptRuntimeSetup);

        // set sys.argv
        SetPyEnv(runtime, pyscript, args);

        // get engine
        ScriptScope scope = runtime.CreateScope();
        ScriptEngine engine = runtime.GetEngine("python");

        ScriptSource source = engine.CreateScriptSourceFromFile(pyscript);
        source.Compile();

        try {
            source.Execute(scope);
        } catch (IronPython.Runtime.Exceptions.SystemExitException e) {
            Console.WriteLine(e.StackTrace);
        }
    }
コード例 #2
0
        public void register()
        {
            engine = Python.CreateEngine();
            scope = null;
            runtime = engine.Runtime;

            scope = runtime.CreateScope();
        }
コード例 #3
0
        public IronPythonScriptEngine()
        {
            runtime = engine.Runtime;
            runtime.LoadAssembly(Assembly.GetAssembly(typeof(Mogre.Vector3)));
            scope = runtime.CreateScope();

            // install built-in scripts
            install(new Script(builtin));
        }
コード例 #4
0
ファイル: Runner.cs プロジェクト: GrahamClark/TestConsoleApp
        public void RunProgram()
        {
            engine = Python.CreateEngine();
            runtime = engine.Runtime;
            scope = runtime.CreateScope();

            RunExpression();

            RunInScope();

            RunFromFile();
        }
コード例 #5
0
        private void ValidateGetItems(ScriptRuntime runtime) {
            ScriptScope scope = runtime.CreateScope();

            var dict = new KeyValuePair<string, object>("var1", 1);
            scope.SetVariable(dict.Key, dict.Value);

            TestHelpers.AreEqualCollections<KeyValuePair<string, object>>(new[] { dict }, scope.GetItems());

            var newDict = new KeyValuePair<string, object>("newVar", "newval");
            scope.SetVariable(newDict.Key, newDict.Value);

            TestHelpers.AreEqualCollections<KeyValuePair<string, object>>(new[] { dict, newDict }, scope.GetItems());
        }
コード例 #6
0
ファイル: Scripting.cs プロジェクト: SandonV/OpenSMO
        public Scripting()
        {
            Host = Python.CreateRuntime();
            Scope = Host.CreateScope();
            Engine = Host.GetEngine("Python");

            PacketHooks = new Dictionary<NSCommand, List<PacketHookCall>>();
            UpdateHooks = new List<UpdateHookCall>();
            ChatHooks = new List<ChatHookCall>();
            ChatCommandHooks = new Dictionary<string, List<ChatCommandHookCall>>();
            NameFormatHooks = new List<NameFormatHookCall>();
            PlayerXPHooks = new List<PlayerXPHookCall>();
        }
コード例 #7
0
ファイル: AnalysisModule.cs プロジェクト: babaq/NeuSys
        public AnalysisModule()
        {
            var t = Directory.GetCurrentDirectory();
            SourcePath = t + "\\Analysis";
            if (!Directory.Exists(SourcePath))
            {
                Directory.CreateDirectory(SourcePath);
            }

            ASRT = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(t+"\\NSCore.dll.config"));
            ASRT.LoadAssembly(Assembly.GetAssembly(typeof(IDevice)));
            ASRT.LoadAssembly(Assembly.GetAssembly(typeof(Marshal)));

            Scope = ASRT.CreateScope();
        }
コード例 #8
0
ファイル: BonsaiTestClass.cs プロジェクト: eugen/Bonsai
        public BonsaiTestClass()
        {
            ScriptRuntimeSetup runtimeSetup = new ScriptRuntimeSetup() {
                DebugMode = true,
                LanguageSetups = {
                      new LanguageSetup(
                        typeof(BonsaiContext).AssemblyQualifiedName,
                        "Bonsai",
                        new string[] {"Bonsai"},
                        new string[] {".bon"})
                }
            };

            ScriptRuntime runtime = new ScriptRuntime(runtimeSetup);
            ScriptScope global = runtime.CreateScope();
            scriptEngineInstance = runtime.GetEngineByTypeName(typeof(BonsaiContext).AssemblyQualifiedName);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: k0st1x/DLR-Usage-Sample
        static void Main(string[] args)
        {
            var runtimeSetup = Python.CreateRuntimeSetup(new Dictionary<string, object>());
            runtimeSetup.DebugMode = true;

            var runtime = new ScriptRuntime(runtimeSetup);

            var scope = runtime.CreateScope(new Dictionary<string, object> {
                { "name" , "Batman" }
            });

            var engine = runtime.GetEngine("py");
            var scriptSource = engine.CreateScriptSourceFromFile("script.py");
            var compiledCode = scriptSource.Compile();

            compiledCode.Execute(scope);
        }
コード例 #10
0
        public RubyEngine(object appScope)
        {
            var runtimeSetup = new ScriptRuntimeSetup();
            runtimeSetup
                .LanguageSetups
                .Add(new LanguageSetup("IronRuby.Runtime.RubyContext, IronRuby",
                                       "IronRuby 1.0",
                                       new[] { "IronRuby", "Ruby", "rb" },
                                       new[] { ".rb" }));

            runtime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, runtimeSetup);

            scope = runtime.CreateScope();
            scope.SetVariable("app", appScope);

            engine = runtime.GetEngine("IronRuby");
        }
コード例 #11
0
ファイル: HAPITestBase.cs プロジェクト: rifraf/iron
        protected HAPITestBase() {
            
            var ses = CreateSetup();
            ses.HostType = typeof(TestHost);
            _runtime = new ScriptRuntime(ses);
            _remoteRuntime = ScriptRuntime.CreateRemote(TestHelpers.CreateAppDomain("Alternate"), ses);

            _runTime = _runtime;// _remoteRuntime;

            _PYEng = _runTime.GetEngine("py");
            _RBEng = _runTime.GetEngine("rb");

            SetTestLanguage();
            
            _defaultScope = _runTime.CreateScope();
            _codeSnippets = new PreDefinedCodeSnippets();
        }
コード例 #12
0
        protected bool eval(string script, object propertyValue)
        {
            ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
            ScriptRuntime runtime = new ScriptRuntime(setup);

            ScriptScope scope = runtime.CreateScope("IronPython");
            scope.SetVariable("property_value", propertyValue);
            scope.SetVariable("result", true);

            scope.Engine.CreateScriptSourceFromString("import clr", SourceCodeKind.SingleStatement).Execute(scope);
            scope.Engine.CreateScriptSourceFromString("clr.AddReference('System')", SourceCodeKind.SingleStatement).Execute(scope);
            scope.Engine.CreateScriptSourceFromString("from System import *", SourceCodeKind.SingleStatement).Execute(scope);
            ScriptSource source = scope.Engine.CreateScriptSourceFromString(script, SourceCodeKind.Statements);
            source.Execute(scope);

            bool result = (bool)scope.GetVariable("result");

            return result;
        }
コード例 #13
0
    static void Main(string[] args)
    {
        // set path for dynamic assembly loading
        AppDomain.CurrentDomain.AssemblyResolve +=
            new ResolveEventHandler(ResolveAssembly);


        string path = System.IO.Path.Combine(exe_path, py_path);

        pyscript = System.IO.Path.Combine(path, pyscript);
        pyscript = System.IO.Path.GetFullPath(pyscript);         // normalize

        // get runtime
        ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup();

        LanguageSetup language = Python.CreateLanguageSetup(null);

        language.Options["Debug"] = true;
        scriptRuntimeSetup.LanguageSetups.Add(language);

        ScriptRuntime runtime = new Microsoft.Scripting.Hosting.ScriptRuntime(scriptRuntimeSetup);

        // set sys.argv
        SetPyEnv(runtime, pyscript, args);

        // get engine
        ScriptScope  scope  = runtime.CreateScope();
        ScriptEngine engine = runtime.GetEngine("python");

        ScriptSource source = engine.CreateScriptSourceFromFile(pyscript);

        source.Compile();

        try {
            source.Execute(scope);
        } catch (IronPython.Runtime.Exceptions.SystemExitException e) {
            Console.WriteLine(e.StackTrace);
        }
    }
コード例 #14
0
ファイル: PyCrust.cs プロジェクト: mdrubin/codevoyeur-samples
        protected object ConstructObject(ContainedObject co)
        {
            if (_staticObjects.ContainsKey(co.Name)) {
                return _staticObjects[co.Name];
            } else {

                //in the full CodeVoyeur version, this is cached!
                ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
                ScriptRuntime runtime = new ScriptRuntime(setup);
                runtime.LoadAssembly(Assembly.GetExecutingAssembly());

                ScriptScope scope = runtime.CreateScope("IronPython");
                ScriptSource source = scope.Engine.CreateScriptSourceFromString("from HostedIronPython.Model import *", SourceCodeKind.SingleStatement);
                source.Execute(scope);

                scope.SetVariable("instance", new object());

                scope.SetVariable("reference", new Func<string, object>
                    (
                        delegate(string refName) {
                            if (_staticObjects.ContainsKey(refName))
                                return _staticObjects[refName];
                            else
                                return GetFilling(refName);
                        }
                    ));

                ScriptSource configSource = scope.Engine.CreateScriptSourceFromString(co.Script, SourceCodeKind.Statements);
                configSource.Execute(scope);

                if (co.IsStatic)
                    return _staticObjects[co.Name] = scope.GetVariable("instance");
                else
                    return scope.GetVariable("instance");
            }
        }
コード例 #15
0
ファイル: Main.cs プロジェクト: eugen/Bonsai
        public static void Main(string[] args)
        {
            ScriptRuntimeSetup runtimeSetup = new ScriptRuntimeSetup() {
                DebugMode = true,
                LanguageSetups = {
                      new LanguageSetup(
                        typeof(BonsaiContext).AssemblyQualifiedName,
                        "Bonsai",
                        new string[] {"Bonsai"},
                        new string[] {".bon"})
                }
            };

            ScriptRuntime runtime = new ScriptRuntime(runtimeSetup);
            ScriptScope global = runtime.CreateScope();
            ScriptEngine engine = runtime.GetEngineByTypeName(typeof(BonsaiContext).AssemblyQualifiedName);

            var result = engine.Execute(File.ReadAllText("Test.bon"));
            string line;
            while((line = Console.ReadLine()).Length > 0) {
                result = engine.Execute(line);
                Console.WriteLine(result);
            }
        }
コード例 #16
0
        private Func<Album, bool> getQuery(string queryName, string searchParam)
        {
            XDocument doc = XDocument.Load("AlbumQueries.xml");

            var query = (from q in doc.Descendants("query")
                           where q.Attribute("name").Value == queryName
                           select new {
                              Query = q.Value
                          }).FirstOrDefault();

            ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
            ScriptRuntime runtime = new ScriptRuntime(setup);

            ScriptScope scope = runtime.CreateScope("IronPython");
            scope.SetVariable("search_param", searchParam);

            scope.Engine.CreateScriptSourceFromString("import clr", SourceCodeKind.SingleStatement).Execute(scope);
            scope.Engine.CreateScriptSourceFromString("clr.AddReference('System')", SourceCodeKind.SingleStatement).Execute(scope);
            scope.Engine.CreateScriptSourceFromString("from System import *", SourceCodeKind.SingleStatement).Execute(scope);
            ScriptSource source = scope.Engine.CreateScriptSourceFromString(query.Query, SourceCodeKind.Statements);
            source.Execute(scope);

            return scope.GetVariable<Func<Album, bool>>("query");
        }
コード例 #17
0
ファイル: PluginStore.cs プロジェクト: welias/IronWASP
        static ScriptEngine GetScriptEngine()
        {
            ScriptRuntimeSetup Setup = new ScriptRuntimeSetup();
            Setup.LanguageSetups.Add(IronRuby.Ruby.CreateRubySetup());
            Setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null));
            ScriptRuntime RunTime = new ScriptRuntime(Setup);
            ScriptEngine Engine = RunTime.GetEngine("py");
            ScriptScope Scope = RunTime.CreateScope();

            Assembly MainAssembly = Assembly.GetExecutingAssembly();
            string RootDir = Directory.GetParent(MainAssembly.Location).FullName;

            RunTime.LoadAssembly(MainAssembly);
            RunTime.LoadAssembly(typeof(String).Assembly);
            RunTime.LoadAssembly(typeof(Uri).Assembly);
            RunTime.LoadAssembly(typeof(XmlDocument).Assembly);

            Engine.Runtime.TryGetEngine("py", out Engine);
            return Engine;
        }
コード例 #18
0
ファイル: IronScripting.cs プロジェクト: moon2l/IronWASP
        internal static void InitialiseScriptingEnvironment()
        {
            ScriptRuntimeSetup Setup = new ScriptRuntimeSetup();
            Setup.LanguageSetups.Add(IronRuby.Ruby.CreateRubySetup());
            Setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null));
            RunTime = new ScriptRuntime(Setup);
            Engine = RunTime.GetEngine("py");
            Scope = RunTime.CreateScope();

            RunTime.IO.SetOutput(ShellOutStream, Encoding.UTF8);
            RunTime.IO.SetErrorOutput(ShellOutStream, Encoding.UTF8);

            Assembly MainAssembly = Assembly.GetExecutingAssembly();
            string RootDir = Directory.GetParent(MainAssembly.Location).FullName;
            string HAGPath = Path.Combine(RootDir, "HtmlAgilityPack.dll");
            Assembly HAGAssembly = Assembly.LoadFile(HAGPath);

            RunTime.LoadAssembly(MainAssembly);
            RunTime.LoadAssembly(HAGAssembly);
            RunTime.LoadAssembly(typeof(String).Assembly);
            RunTime.LoadAssembly(typeof(Uri).Assembly);
            RunTime.LoadAssembly(typeof(XmlDocument).Assembly);

            Engine.Runtime.TryGetEngine("py", out Engine);
            List<string> PySearchPaths = new List<string>();
            foreach (string PyPath in PyPaths)
            {
                PySearchPaths.Add(PyPath.Replace("$ROOTDIR", RootDir));
            }
            try
            {
                Engine.SetSearchPaths(PySearchPaths);
            }
            catch(Exception Exp)
            {
                IronException.Report("Unable to set PyPaths", Exp.Message, Exp.StackTrace);
            }

            foreach (string PyCommand in PyCommands)
            {
                try
                {
                    ExecuteStartUpCommand(PyCommand);
                }
                catch(Exception Exp)
                {
                    IronException.Report("Unable to execute Python startup command - " + PyCommand, Exp.Message, Exp.StackTrace);
                }
            }

            Engine.Runtime.TryGetEngine("rb", out Engine);

            List<string> RbSearchPaths = new List<string>();

            foreach (string RbPath in RbPaths)
            {
                RbSearchPaths.Add(RbPath.Replace("$ROOTDIR", RootDir));
            }
            Engine.SetSearchPaths(RbSearchPaths);

            foreach (string RbCommand in RbCommands)
            {
                try
                {
                    ExecuteStartUpCommand(RbCommand);
                }
                catch (Exception Exp)
                {
                    IronException.Report("Unable to execute Ruby startup command" + RbCommand, Exp.Message, Exp.StackTrace);
                }
            }

            Engine.Runtime.TryGetEngine("py", out Engine);
            ExecuteStartUpCommand("print 123");
            ShellOutText = new StringBuilder();
            IronUI.ResetInteractiveShellResult();
        }
コード例 #19
0
 public void RestartShell(bool displayRestart)
 {
     environment = new ScriptRuntime(scriptRuntimeSetup);
     scope = environment.CreateScope();
     engine = environment.GetEngine("py");
     if (System.Environment.OSVersion.Platform == System.PlatformID.Unix)
     {
         engine.SetSearchPaths(new string[] {
             "/home/dblank/Myro/Pyjama/python",
             "/usr/lib/python2.5",
             "/usr/lib/python2.5/site-packages"});
     }
     else
     {
         engine.SetSearchPaths(new string[] {
             Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory)
                 + @"\Myro\Pyjama\python",
             @"C:\Python25\Lib",
             @"C:\Python25\site-packages"
             });
     }
     // Load mscorlib.dll:
     engine.Runtime.LoadAssembly(typeof(string).Assembly);
     // Load Languages so that Host System can find DLLs:
     engine.Runtime.LoadAssembly(typeof(IronPython.Hosting.Python).Assembly);
     engine.Runtime.LoadAssembly(typeof(IronRuby.Hosting.RubyCommandLine).Assembly);
     engine.Runtime.LoadAssembly(typeof(IronRuby.StandardLibrary.BigDecimal.Fraction).Assembly);
     //Load System.dll
     engine.Runtime.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly);
     if (displayRestart)
     DisplayError("========= Restart =========");
 }
コード例 #20
0
 private void CreateScriptingParts()
 {
     _engine = Python.CreateEngine(); // create python engine
     _runtime = _engine.Runtime; // create the runtime for the engine
     _scope = _runtime.CreateScope(); // create the scope in which you are going to execute the script
 }
コード例 #21
0
ファイル: DynamicEngine.cs プロジェクト: BenHall/ironruby
 /// <summary>
 /// Creates a new scope, adding any convenience globals and modules.
 /// </summary>
 public static ScriptScope CreateScope(ScriptRuntime runtime) {
     var scope = runtime.CreateScope();
     scope.SetVariable("document", HtmlPage.Document);
     scope.SetVariable("window", HtmlPage.Window);
     if (DynamicApplication.Current != null) {
         scope.SetVariable("me", DynamicApplication.Current.RootVisual);
         scope.SetVariable("xaml", DynamicApplication.Current.RootVisual);
     }
     return scope;
 }
コード例 #22
0
        private void InitIronPython()
        {
            if (m_engine == null)
            {
                //s_engine = Python.CreateEngine();
                //s_runtime = s_engine.Runtime;
                // s_scope = s_engine.CreateScope();

                m_runtime = Python.CreateRuntime();
                m_runtime.LoadAssembly(typeof(String).Assembly);
                //runtime.LoadAssembly(typeof(Uri).Assembly);

                // no module name System
                //m_runtime.ImportModule("System");

                m_scope = m_runtime.CreateScope();

                m_engine = Python.GetEngine(m_runtime);

                ICollection<string> paths = m_engine.GetSearchPaths();
                foreach (string s in s_pythonLibPath)
                {
                    paths.Add(s);
                }
                m_engine.SetSearchPaths(paths);
            }
        }