internal static Tuple <double, bool> convertToFloat(LuaValue luaValue) { switch (luaValue.value.GetType().Name) { case "Double": return(Tuple.Create(luaValue.toFloat(), true)); case "Int64": return(Tuple.Create(luaValue.toFloat(), true)); case "String": return(number.Parser.ParseFloat(Convert.ToString(luaValue.value))); default: return(Tuple.Create(0d, false)); } }
LuaValue _floatToInteger(LuaValue key) { if (key.isFloat()) { var f = key.toFloat(); return(new LuaValue(Math.FloatToInteger(f).Item1)); } return(key); }
object _floatToInteger(object key) { if (LuaValue.isFloat(key)) { var f = LuaValue.toFloat(key); return(Math.FloatToInteger(f).Item1); } return(key); }
public void put(LuaValue key, LuaValue val) { if (key == null) { throw new Exception("table index is nil!"); } if (key.isFloat() && double.IsNaN(key.toFloat())) { throw new Exception("table index is NaN!"); } key = _floatToInteger(key); if (key.isInteger()) { var idx = key.toInteger(); if (idx >= 1) { var arrLen = arr.Length; if (idx <= arrLen) { arr[idx - 1] = val; if (idx == arrLen && val.value == null) { _shrinkArray(); } return; } if (idx == arrLen + 1) { _map.Remove(idx); if (val != null) { var b = arr.ToList(); b.Add(val); arr = b.ToArray(); _expandArray(); } return; } } } if (val != null) { if (_map == null) { _map = new Dictionary <object, LuaValue>(8); } _map.Add(key.value, val); } else { _map.Remove(key.value); } }
public void put(object key, object val) { if (key == null) { throw new Exception("table index is nil!"); } if (LuaValue.isFloat(key) && double.IsNaN(LuaValue.toFloat(key))) { throw new Exception("table index is NaN!"); } key = _floatToInteger(key); if (LuaValue.isInteger(key)) { var idx = LuaValue.toInteger(key); if (idx >= 1) { var arrLen = arr?.Length ?? 0; if (idx <= arrLen) { arr[idx - 1] = val; if (idx == arrLen && val == null) { _shrinkArray(); } return; } if (idx == arrLen + 1) { _map?.Remove(idx); if (val != null) { if (arr == null) { var b = new List <object> { val }; arr = b.ToArray(); _expandArray(); } else { var b = arr.ToList(); b.Add(val); arr = b.ToArray(); _expandArray(); } } return; } } } if (val != null) { if (_map == null) { _map = new Dictionary <object, object>(8); } if (!_map.ContainsKey(key)) { _map.Add(key, val); } else { _map[key] = val; } } else { _map.Remove(key); } }