Exemplo n.º 1
0
        public LuaValue Execute(out bool isBreak)
        {
            foreach (Statement statement in Statements)
            {
                ReturnStmt returnStmt = statement as ReturnStmt;
                if (returnStmt != null)
                {
                    isBreak = false;
                    //[PixelCrushers]return LuaMultiValue.WrapLuaValues(returnStmt.ExprList.ConvertAll(expr => expr.Evaluate(this.Enviroment)).ToArray());
                    return(LuaMultiValue.WrapLuaValues(LuaInterpreterExtensions.EvaluateAll(returnStmt.ExprList, this.Enviroment).ToArray()));
                }
                else if (statement is BreakStmt)
                {
                    isBreak = true;
                    return(null);
                }
                else
                {
                    var returnValue = statement.Execute(this.Enviroment, out isBreak);
                    if (returnValue != null || isBreak == true)
                    {
                        return(returnValue);
                    }
                }
            }

            isBreak = false;
            return(null);
        }
Exemplo n.º 2
0
        public override LuaValue Evaluate(LuaValue baseValue, LuaTable enviroment)
        {
            LuaValue    value    = LuaValue.GetKeyValue(baseValue, new LuaString(this.Method));
            LuaFunction function = value as LuaFunction;

            if (function != null)
            {
                if (this.Args.Table != null)
                {
                    return(function.Function.Invoke(new LuaValue[] { baseValue, this.Args.Table.Evaluate(enviroment) }));
                }
                else if (this.Args.String != null)
                {
                    return(function.Function.Invoke(new LuaValue[] { baseValue, this.Args.String.Evaluate(enviroment) }));
                }
                else
                {
                    //[PixelCrushers]List<LuaValue> args = this.Args.ArgList.ConvertAll(arg => arg.Evaluate(enviroment));
                    List <LuaValue> args = LuaInterpreterExtensions.EvaluateAll(this.Args.ArgList, enviroment);
                    args.Insert(0, baseValue);
                    return(function.Function.Invoke(args.ToArray()));
                }
            }
            else
            {
                throw new Exception("Invoke method call on non function value.");
            }
        }
Exemplo n.º 3
0
        public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
        {
            //[PixelCrushers]LuaValue[] values = this.ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray();
            LuaValue[] values = LuaInterpreterExtensions.EvaluateAll(this.ExprList, enviroment).ToArray();

            LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values);

            for (int i = 0; i < Math.Min(this.VarList.Count, neatValues.Length); i++)
            {
                Var var = this.VarList[i];

                if (var.Accesses.Count == 0)
                {
                    VarName varName = var.Base as VarName;

                    if (varName != null)
                    {
                        SetKeyValue(enviroment, new LuaString(varName.Name), values[i]);
                        continue;
                    }
                }
                else
                {
                    LuaValue baseValue = var.Base.Evaluate(enviroment);

                    for (int j = 0; j < var.Accesses.Count - 1; j++)
                    {
                        Access access = var.Accesses[j];

                        baseValue = access.Evaluate(baseValue, enviroment);
                    }

                    Access lastAccess = var.Accesses[var.Accesses.Count - 1];

                    NameAccess nameAccess = lastAccess as NameAccess;
                    if (nameAccess != null)
                    {
                        if (baseValue == null || (baseValue is LuaNil))
                        {
                            throw new System.NullReferenceException("Cannot assign to a null value. Are you trying to assign to a nonexistent table element?.");
                        }
                        SetKeyValue(baseValue, new LuaString(nameAccess.Name), values[i]);
                        continue;
                    }

                    KeyAccess keyAccess = lastAccess as KeyAccess;
                    if (lastAccess != null)
                    {
                        SetKeyValue(baseValue, keyAccess.Key.Evaluate(enviroment), values[i]);
                    }
                }
            }

            isBreak = false;
            return(null);
        }
        public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
        {
            //[PixelCrushers]LuaValue[] values = this.ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray();
            LuaValue[] values = LuaInterpreterExtensions.EvaluateAll(this.ExprList, enviroment).ToArray();

            LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values);

            LuaFunction func    = neatValues[0] as LuaFunction;
            LuaValue    state   = neatValues[1];
            LuaValue    loopVar = neatValues[2];

            var table = new LuaTable(enviroment);

            this.Body.Enviroment = table;

            while (true)
            {
                LuaValue      result     = func.Invoke(new LuaValue[] { state, loopVar });
                LuaMultiValue multiValue = result as LuaMultiValue;

                if (multiValue != null)
                {
                    neatValues = LuaMultiValue.UnWrapLuaValues(multiValue.Values);
                    loopVar    = neatValues[0];

                    for (int i = 0; i < Math.Min(this.NameList.Count, neatValues.Length); i++)
                    {
                        table.SetNameValue(this.NameList[i], neatValues[i]);
                    }
                }
                else
                {
                    loopVar = result;
                    table.SetNameValue(this.NameList[0], result);
                }

                if (loopVar == LuaNil.Nil)
                {
                    break;
                }

                var returnValue = this.Body.Execute(out isBreak);
                if (returnValue != null || isBreak == true)
                {
                    isBreak = false;
                    return(returnValue);
                }
            }

            isBreak = false;
            return(null);
        }
        public override LuaValue Evaluate(LuaValue baseValue, LuaTable enviroment)
        {
            LuaFunction function = baseValue as LuaFunction;

            if (function != null)
            {
                //[PixelCrushers] Removed (not WinRT compatible, and not needed for Dialogue System)
                //if (function.Function.Method.DeclaringType.FullName == "Language.Lua.Library.BaseLib" &&
                //    (function.Function.Method.Name == "loadstring" || function.Function.Method.Name == "dofile"))
                //{
                //    if (this.Args.String != null)
                //    {
                //        return function.Function.Invoke(new LuaValue[] { this.Args.String.Evaluate(enviroment), enviroment });
                //    }
                //    else
                //    {
                //        return function.Function.Invoke(new LuaValue[] { this.Args.ArgList[0].Evaluate(enviroment), enviroment });
                //    }
                //}

                if (this.Args.Table != null)
                {
                    return(function.Function.Invoke(new LuaValue[] { this.Args.Table.Evaluate(enviroment) }));
                }
                else if (this.Args.String != null)
                {
                    return(function.Function.Invoke(new LuaValue[] { this.Args.String.Evaluate(enviroment) }));
                }
                else
                {
                    //[PixelCrushers] Was: List<LuaValue> args = this.Args.ArgList.ConvertAll(arg => arg.Evaluate(enviroment));
                    List <LuaValue> args = LuaInterpreterExtensions.EvaluateAll(this.Args.ArgList, enviroment);
                    return(function.Function.Invoke(LuaMultiValue.UnWrapLuaValues(args.ToArray())));
                }
            }
            else
            {
                //[PixelCrushers Was: throw new Exception("Invoke function call on non function value.");
                throw new Exception("Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?");
            }
        }
        public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
        {
            //[PixelCrushers]LuaValue[] values = this.ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray();
            LuaValue[] values = LuaInterpreterExtensions.EvaluateAll(this.ExprList, enviroment).ToArray();

            LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values);

            for (int i = 0; i < Math.Min(this.NameList.Count, neatValues.Length); i++)
            {
                enviroment.RawSetValue(this.NameList[i], neatValues[i]);
            }

            if (neatValues.Length < this.NameList.Count)
            {
                for (int i = neatValues.Length; i < this.NameList.Count - neatValues.Length; i++)
                {
                    enviroment.RawSetValue(this.NameList[i], LuaNil.Nil);
                }
            }

            isBreak = false;
            return(null);
        }