/// <summary> /// Runs the Statement /// </summary> /// <param name="enviroment">The environment to run in</param> /// <param name="isBreak">whether to break execution or not</param> /// <returns></returns> public override LuaValue Execute(LuaTable enviroment, out bool isBreak) { LuaValue[] values = this.ExprList.ConvertAll(expr => expr.Evaluate(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) { // inital creation, no metatable yet 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 KeyAccess ParseKeyAccess(out bool success) { var reskey = new Tuple<int, string>(position, "KeyAccess"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as KeyAccess; } int errorCount = Errors.Count; KeyAccess keyAccess = new KeyAccess(); int start_position = position; MatchTerminal('[', out success); if (!success) { position = start_position; ParsingResults[reskey] = new Tuple<object, bool, int>(keyAccess, success, position);return keyAccess; } ParseSpOpt(out success); keyAccess.Key = ParseExpr(out success); if (!success) { Error("Failed to parse Key of KeyAccess."); position = start_position; ParsingResults[reskey] = new Tuple<object, bool, int>(keyAccess, success, position);return keyAccess; } MatchTerminal(']', out success); if (!success) { Error("Failed to parse ']' of KeyAccess."); position = start_position; } if (success) { ClearError(errorCount); } ParsingResults[reskey] = new Tuple<object, bool, int>(keyAccess, success, position); return keyAccess; }