public override LuaValue Execute(LuaTable enviroment, out bool isBreak) { LuaNumber start = Start.Evaluate(enviroment) as LuaNumber; LuaNumber end = End.Evaluate(enviroment) as LuaNumber; double step = 1; if (Step != null) { step = (Step.Evaluate(enviroment) as LuaNumber).Number; } var table = new LuaTable(enviroment); table.SetNameValue(VarName, start); Body.Enviroment = table; while (step > 0 && start.Number <= end.Number || step <= 0 && start.Number >= end.Number) { var returnValue = Body.Execute(out isBreak); if (returnValue != null || isBreak == true) { isBreak = false; return(returnValue); } start.Number += step; } isBreak = false; return(null); }
public LuaValue GetValue(LuaValue key) { if (key == LuaNil.Nil) { return(LuaNil.Nil); } else { LuaNumber number = key as LuaNumber; if (number != null && number.Number == (int)number.Number) { int index = (int)number.Number; if (index > 0 && index <= this.Length) { return(this.list[index - 1]); } } if (this.dict != null && this.dict.ContainsKey(key)) { return(this.dict[key]); } if (this.MetaTable != null) { return(this.GetValueFromMetaTable(key)); } return(LuaNil.Nil); } }
public void SetKeyValue(LuaValue key, LuaValue value) { LuaNumber number = key as LuaNumber; if (number != null && number.Number == (int)number.Number) { int index = (int)number.Number; if (index == this.Length + 1) { this.AddValue(value); return; } if (index > 0 && index <= this.Length) { this.list[index - 1] = value; return; } } if (value == LuaNil.Nil) { this.RemoveKey(key); return; } if (this.dict == null) { this.dict = new Dictionary <LuaValue, LuaValue>(); } this.dict[key] = value; }
public void SetKeyValue(LuaValue key, LuaValue value) { LuaNumber number = key as LuaNumber; if (number != null && number.Number == (int)number.Number) { int index = (int)number.Number; if (m_intKeyCache.ContainsKey(index)) //[PixelCrushers] { Dict[m_intKeyCache[index]] = value; return; } if (index == this.Length + 1) { this.AddValue(value); return; } if (index > 0 && index <= this.Length) { this.list[index - 1] = value; return; } } if (value == LuaNil.Nil) { this.RemoveKey(key); return; } if (this.dict == null) { this.dict = new Dictionary <LuaValue, LuaValue>(); } this.dict[key] = value; //[PixelCrushers] Update caches: int intValue; if (GetIntValue(key, out intValue)) { m_intKeyCache[intValue] = key; } else if (key is LuaString) { m_stringKeyCache[(key as LuaString).Text] = key; } }
public void AddRaw(int key, LuaValue value) //[PixelCrushers] { if (key == this.Length + 1) { this.AddValue(value); } else if (key > 0 && key <= this.Length) { this.list[key - 1] = value; } else { var keyValue = new LuaNumber(key); Dict[keyValue] = value; m_intKeyCache[key] = keyValue; } }
private static int?Compare(LuaValue leftValue, LuaValue rightValue) { LuaNumber left = leftValue as LuaNumber; LuaNumber right = rightValue as LuaNumber; if (left != null && right != null) { return(left.Number.CompareTo(right.Number)); } LuaString leftString = leftValue as LuaString; LuaString rightString = rightValue as LuaString; if (leftString != null && rightString != null) { return(StringComparer.Ordinal.Compare(leftString.Text, rightString.Text)); } return(null); }
public void Sort() { this.list.Sort((a, b) => { LuaNumber n = a as LuaNumber; LuaNumber m = b as LuaNumber; if (n != null && m != null) { return(n.Number.CompareTo(m.Number)); } LuaString s = a as LuaString; LuaString t = b as LuaString; if (s != null && t != null) { return(s.Text.CompareTo(t.Text)); } return(0); }); }
public bool ContainsKey(LuaValue key) { if (this.dict != null) { if (this.dict.ContainsKey(key)) { return(true); } } if (this.list != null) { LuaNumber index = key as LuaNumber; if (index != null && index.Number == (int)index.Number) { return(index.Number >= 1 && index.Number <= this.list.Count); } } return(false); }