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) { 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); }
private VarName ParseVarName(out bool success) { var reskey = new Tuple2<int, string>(position, "VarName"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as VarName; } int errorCount = Errors.Count; VarName varName = new VarName(); varName.Name = ParseName(out success); if (success) { ClearError(errorCount); } else { Error("Failed to parse Name of VarName."); } ParsingResults[reskey] = new Tuple3<object, bool, int>(varName, success, position); return varName; }