public void Execute()
 {
     _compiledCode.Execute();
 }
        /// <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;
        }
 public object ExecuteWithResult(CompiledCode compiledCode, object[] values)
 {
     SetVariables(this.ScriptScope, values);
     return ExecuteSafely(() => compiledCode.Execute(this.ScriptScope));
 }
示例#4
0
 internal static void ExecuteCompiledCode(CompiledCode compiledExpression, ScriptScope module)
 {
     try {
         compiledExpression.Execute(module);
     } catch (Exception e) {
         if (!ProcessRuntimeException(compiledExpression.Engine, e, null))
             throw;
     }
 }
示例#5
0
 internal static void ExecuteCode(ScriptScope scope, CompiledCode compiledCode, string virtualPath)
 {
     try {
         compiledCode.Execute(scope);
     } catch (SyntaxErrorException e) {
         EngineHelper.ThrowSyntaxErrorException(e);
     } catch (Exception e) {
         if (!EngineHelper.ProcessRuntimeException(compiledCode.Engine, e, virtualPath))
             throw;
     }
 }
示例#6
0
 internal static object EvaluateCompiledCode(CompiledCode compiledExpression, ScriptScope scope,
     string defaultVirtualPath, int lineOffset)
 {
     try {
         return compiledExpression.Execute(scope);
     } catch (Exception e) {
         if (!ProcessRuntimeException(compiledExpression.Engine, e, defaultVirtualPath, lineOffset))
             throw;
     }
     return null;
 }
示例#7
0
 public static dynamic ExecuteCompiledCode(CompiledCode code, ICompiledCodeContext context)
 {
     var scope = CurrentScriptEngine.CreateScope();
     EvaluateContext(scope, context);
     return code.Execute(scope);
 }
示例#8
0
 public virtual object Run()
 {
     if (Source != null)
     {
         CCode = Source.Compile();
         return CCode.Execute(Scope);
     }
     else
     {
         MessageBox.Show("No Script Source Loaded !");
         return null;
     }
 }