コード例 #1
0
ファイル: Main.cs プロジェクト: elliotharris/AxScript
 public static void InitExitHandler(AxInterpreter ax, AxFunction func)
 {
     ax.ScriptError += exception => func.Call<Boolean>(ax, new object[] {EXIT_CODE_ERROR, exception});
     ax.ScriptEnd += exception => func.Call<Boolean>(ax, new object[] { EXIT_CODE_CLEAN, exception });
 }
コード例 #2
0
 public void While(dynamic cond, AxFunction Do)
 {
     if (cond is AxVariablePtr)
     {
         while (Variables[cond])
         {
             Do.Call(this, null);
         }
     }
     else if (cond is Boolean)
     {
         throw new AxException(this, "Using a Boolean directly will mean it wont get updated, you need to use a variable pointer.");
     }
     else if (cond is AxFunction)
     {
         while ((bool) cond.Call(this, null))
         {
             Do.Call(this, null);
         }
     }
 }
コード例 #3
0
        private void GetFunctions()
        {
            for (var i = 0; i < Script.Length; i++)
            {
                if (Script[i] != '~' || Script[i + 1] != '(') continue;
                var func = Extract(Script.Substring(i));
                if (func.Item2 != -1)
                {
                    var functionString = func.Item1;

                    var indexOfColon = functionString.IndexOf(':');
                    var indexOfParenthesis = functionString.IndexOf('(');
                    var indexOfPeriod = functionString.IndexOf('|');

                    var functionName = functionString.Substring(0, indexOfColon);
                    //Console.WriteLine (FunctionName);
                    string[] functionParameters;
                    string functionContents;
                    if (indexOfPeriod != -1 && indexOfParenthesis > indexOfPeriod)
                    {
                        functionParameters = functionString.Substring(indexOfColon + 1, indexOfPeriod - indexOfColon - 1).Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(x => Prefix + x).ToArray();
                        functionContents = functionString.Substring(indexOfPeriod + 1);
                    }
                    else
                    {
                        functionParameters = new string[0];
                        functionContents = functionString.Substring(indexOfParenthesis);
                    }
                    var functionFixedParams = !functionParameters.Contains("...");
                    var axFunc = new AxFunction(functionParameters, functionContents, Prefix, functionFixedParams);
                    axFunc.GetDynamicTags();
                    Functions.Add(Prefix + functionName, axFunc);
                    if (axFunc.Tags.ContainsKey("EntryPoint"))
                    {
                        EntryPoint = functionName;
                    }

                    foreach (var t in axFunc.Tags.Where(t => Hooks.ContainsKey(t.Key)))
                    {
                        Hooks[t.Key].Call(this, axFunc);
                    }

                    i += func.Item2;
                }
                else
                {
                    Console.WriteLine("Invalid function");
                }
            }
        }
コード例 #4
0
 public bool Not(AxFunction input)
 {
     return !(bool) input.Call(this, null);
 }
コード例 #5
0
 public void IfElse(bool cond, AxFunction then, AxFunction elseF)
 {
     if (cond)
     {
         then.Call(this, null);
     }
     else
     {
         elseF.Call(this, null);
     }
 }
コード例 #6
0
 public void If(bool cond, AxFunction then)
 {
     if (cond)
     {
         then.Call(this, null);
     }
 }
コード例 #7
0
 public void For(object range, AxFunction func)
 {
     var r = (IEnumerable) range;
     foreach (var b in from object v in r select func.ParamCount == 1 ? new Dictionary<string, object> {{func.Parameters[0], v}} : new Dictionary<string, object>())
     {
         func.Call(this, b);
     }
 }
コード例 #8
0
 public void Do(AxFunction Do, AxFunction cond)
 {
     do
     {
         Do.Call(this, null);
     } while ((bool) cond.Call(this, null));
 }