protected object ExecuteCommand(ScriptSource source) { ErrorListener errorListener = new ErrorSinkProxyListener(ErrorSink); CompiledCode compiledCode = source.Compile(_engine.GetCompilerOptions(_scope), errorListener); return(_commandDispatcher.Execute(compiledCode, _scope)); }
public ScriptErrorSink() { Errors = new List <ScriptError>(); Listener = new ErrorSinkProxyListener(this); }
protected object ExecuteCommand(ScriptSource source) { ErrorListener errorListener = new ErrorSinkProxyListener(ErrorSink); CompiledCode compiledCode = source.Compile(_engine.GetCompilerOptions(_scope), errorListener); return _commandDispatcher.Execute(compiledCode, _scope); }
/// <summary> /// Starts the $PythonBehaviour /// </summary> /// <param name="classname">Name of the Script</param> public bool Awakening(String classname) { scope = engine.CreateScope(); scope.SetVariable("this", this); scope.SetVariable("gameObject", gameObject); scope.SetVariable("transform", transform); scope.SetVariable("enabled", enabled); scope.SetVariable("useAPI", new Action(UseAPI)); scope.SetVariable("disableAPI", new Action(DisableAPI)); if (Settings.useAPI) { Besiege.SetUp(); scope.SetVariable("besiege", Besiege._besiege); } spaar.ModLoader.Game.OnSimulationToggle += GameOnOnSimulationToggle; spaar.ModLoader.Game.OnLevelWon += GameOnOnLevelWon; foreach (string @ref in refs.Where(@ref => !String.IsNullOrEmpty(@ref))) { try { #region OBSOLETE /* * Assembly assembly = Assembly.Load(@ref); * var namespaces = assembly.GetTypes() * .Select(t => t.Namespace) * .Distinct(); * String[] lines = Util.splitStringAtNewline(sauce); * for (int i = 0; i < lines.Length; i++) * { * if (!lines[i].Contains("import") && !String.IsNullOrEmpty(lines[i])) * { * foreach (string ns in namespaces) * { * if (!String.IsNullOrEmpty(ns)) * { * if (lines[i].Contains((ns + "."))) * { * lines[i] = Regex.Replace(lines[i], ns + ".", string.Empty); * } * } * } * } * lines[i] += Util.getNewLine(); * } * lines = lines.Where(x => !string.IsNullOrEmpty(x) && !x.Equals("\r\n") && !x.Equals("\r") && !x.Equals("\n") && !String.IsNullOrEmpty(x.Trim())).ToArray(); * sauce = String.Concat(lines); */ #endregion engine.Runtime.LoadAssembly(Assembly.Load(@ref)); } catch (Exception ex) { Debug.LogException(ex); return(false); } } ScriptSource source = engine.CreateScriptSourceFromString(sauce); ErrorListener error = new ErrorSinkProxyListener(ErrorSink.Default); code = source.Compile(error); if (code == null) { Debug.LogError(error); return(false); } code.Execute(scope); pythonClass = engine.Operations.Invoke(scope.GetVariable(classname)); CallMethod("Awake"); return(true); }