public LuaValue Execute(out bool isBreak) { foreach (Statement statement in Statements) { ReturnStmt returnStmt = statement as ReturnStmt; if (returnStmt != null) { isBreak = false; return(LuaMultiValue.WrapLuaValues(returnStmt.ExprList.ConvertAll(expr => expr.Evaluate(Enviroment)).ToArray())); } else if (statement is BreakStmt) { isBreak = true; return(null); } else { var returnValue = statement.Execute(Enviroment, out isBreak); if (returnValue != null || isBreak == true) { return(returnValue); } } } 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); 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 Execute(LuaTable enviroment, out bool isBreak) { LuaValue[] values = ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray(); LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values); for (int i = 0; i < Math.Min(VarList.Count, neatValues.Length); i++) { Var var = 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) { 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 static LuaValue[] UnWrapLuaValues(LuaValue[] values) { if (values == null || values.Length == 0 || ContainsMultiValue(values) == false) { return(values); } if (values.Length == 1 && values[0] is LuaMultiValue) { return((values[0] as LuaMultiValue).Values); } List <LuaValue> neatValues = new List <LuaValue>(values.Length); for (int i = 0; i < values.Length - 1; i++) { LuaValue value = values[i]; LuaMultiValue multiValue = value as LuaMultiValue; if (multiValue != null) { neatValues.Add(multiValue.Values[0]); } else { neatValues.Add(value); } } LuaValue lastValue = values[values.Length - 1]; LuaMultiValue lastMultiValue = lastValue as LuaMultiValue; if (lastMultiValue != null) { neatValues.AddRange(lastMultiValue.Values); } else { neatValues.Add(lastValue); } return(neatValues.ToArray()); }
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) { LuaValue[] values = ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray(); LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values); for (int i = 0; i < Math.Min(NameList.Count, neatValues.Length); i++) { enviroment.RawSetValue(NameList[i], neatValues[i]); } if (neatValues.Length < NameList.Count) { for (int i = neatValues.Length; i < NameList.Count - neatValues.Length; i++) { enviroment.RawSetValue(NameList[i], LuaNil.Nil); } } isBreak = false; return(null); }
public override LuaValue Evaluate(LuaValue baseValue, LuaTable enviroment) { LuaFunction function = baseValue as LuaFunction; if (function != null) { if (function.Function.Method.DeclaringType.FullName == "Language.Lua.Library.BaseLib" && (function.Function.Method.Name == "loadstring" || function.Function.Method.Name == "dofile")) { if (Args.String != null) { return(function.Function.Invoke(new LuaValue[] { Args.String.Evaluate(enviroment), enviroment })); } else { return(function.Function.Invoke(new LuaValue[] { Args.ArgList[0].Evaluate(enviroment), enviroment })); } } if (Args.Table != null) { return(function.Function.Invoke(new LuaValue[] { Args.Table.Evaluate(enviroment) })); } else if (Args.String != null) { return(function.Function.Invoke(new LuaValue[] { Args.String.Evaluate(enviroment) })); } else { List <LuaValue> args = Args.ArgList.ConvertAll(arg => arg.Evaluate(enviroment)); return(function.Function.Invoke(LuaMultiValue.UnWrapLuaValues(args.ToArray()))); } } else { throw new Exception("Invoke function call on non function value."); } }
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); }