UseFile() public method

path is null file extension does not map to language engine language does not have any search paths file does exist in language's search path
public UseFile ( string path ) : ScriptScope
path string
return ScriptScope
コード例 #1
0
        private void UpdateScript(string script)
        {
            LogTo.Debug("A script was changed - {0}", script);

            if (File.Exists(script))
            {
                _runtime.Shutdown();
                _runtime = Python.CreateRuntime();
                try
                {
                    _script = _runtime.UseFile(script);
                    LogTo.Info("Script loaded");
                    ScriptScope scope = _script;
                    dynamic parser = scope.GetVariable("ParserScript");
                    name = parser.Name;
                    version = parser.Version;
                    author = parser.Author;
                    LogTo.Info("Name: {0}, Version: {1}, Author: {2}", name, version, author);
                }
                catch (SyntaxErrorException e)
                {
                    LogTo.ErrorException("Syntax error", e);
                }
                catch (Exception e)
                {
                    LogTo.WarnException("Script error", e);
                }
            }
            else
            {
                LogTo.Error("Script not loaded (file doesn't exist)");
            }
        }
コード例 #2
0
        private void UpdateScript(string script)
        {
            Log.Debug("A script was changed - {0}", script);

            //scriptStr = File.ReadAllText("interpreter.py");
            //source = engine.CreateScriptSourceFromString(scriptStr, "py");

            if (File.Exists(script))
            {
                _runtime.Shutdown();
                _runtime = Python.CreateRuntime();
                try
                {
                    _script = _runtime.UseFile(script);
                    Log.Info("Script loaded");
                    ScriptScope scope = _script;
                    dynamic parserScript = scope.GetVariable("ParserScript");
                    dynamic parser = parserScript();
                    string name = parser.Name;
                    string version = parser.Version;
                    string author = parser.Author;
                    Log.Info("Name: {0}, Version: {1}, Author: {2}", name, version, author);
                }
                catch (SyntaxErrorException e)
                {
                    Log.ErrorException("Syntax error", e);
                }
            }
            else
            {
                Log.Error("Script not loaded (file doesn't exist)");
            }
        }