private StkId NewTableKey(ref TValue k) { if (k.TtIsNil()) { L.G_RunError("table index is nil"); } if (k.TtIsNumber() && System.Double.IsNaN(k.NValue)) { L.G_RunError("table index is NaN"); } var mp = GetHashNode(ref k); // if main position is taken if (!mp.Val.V.TtIsNil() || mp == DummyNode) { var n = GetFreePos(); if (n == null) { Rehash(ref k); var cell = Get(ref k); if (cell != TheNilValue) { return(cell); } return(NewTableKey(ref k)); } Utl.Assert(n != DummyNode); var othern = GetHashNode(ref mp.Key.V); // is colliding node out of its main position? if (othern != mp) { while (othern.Next != mp) { othern = othern.Next; } othern.Next = n; n.CopyFrom(mp); mp.Next = null; mp.Val.V.SetNilValue(); } // colliding node is in its own main position else { n.Next = mp.Next; mp.Next = n; mp = n; } } mp.Key.V.SetObj(ref k); Utl.Assert(mp.Val.V.TtIsNil()); return(mp.Val); }
private bool IsFalse(ref TValue v) { if (v.TtIsNil()) { return(true); } if ((v.TtIsBoolean() && v.BValue() == false)) { return(true); } return(false); }
public T GetValue <T>(TValue v) { var t = typeof(T); if (t.IsEnum) { t = Enum.GetUnderlyingType(t); } switch ((LuaType)v.Tt) { case LuaType.LUA_TNIL: return(default(T)); case LuaType.LUA_TBOOLEAN: bool b = !v.TtIsNil() && (!v.TtIsBoolean() || v.BValue()); return((T)(object)b); case LuaType.LUA_TLIGHTUSERDATA: return((T)v.OValue); case LuaType.LUA_TNUMBER: if (t == typeof(object) && v.NValue >= int.MinValue && v.NValue <= int.MaxValue && v.NValue == (int)v.NValue) { t = typeof(int); } return((T)Convert.ChangeType(v.NValue, t)); case LuaType.LUA_TSTRING: return((T)v.OValue); case LuaType.LUA_TTABLE: case LuaType.LUA_TFUNCTION: case LuaType.LUA_TTHREAD: return((T)v.OValue); case LuaType.LUA_TUINT64: return((T)Convert.ChangeType(v.UInt64Value, t)); default: return(default(T)); } }
private StkId NewTableKey(ref TValue k) { if(k.TtIsNil()) { L.G_RunError("table index is nil"); } if(k.TtIsNumber() && System.Double.IsNaN(k.NValue)) { L.G_RunError("table index is NaN"); } var mp = GetHashNode(ref k); // if main position is taken if(!mp.Val.V.TtIsNil() || mp == DummyNode) { var n = GetFreePos(); if(n == null) { Rehash(ref k); var cell = Get(ref k); if(cell != TheNilValue) { return cell; } return NewTableKey(ref k); } Utl.Assert(n != DummyNode); var othern = GetHashNode(ref mp.Key.V); // is colliding node out of its main position? if(othern != mp) { while(othern.Next != mp) { othern = othern.Next; } othern.Next = n; n.CopyFrom(mp); mp.Next = null; mp.Val.V.SetNilValue(); } // colliding node is in its own main position else { n.Next = mp.Next; mp.Next = n; mp = n; } } mp.Key.V.SetObj(ref k); Utl.Assert(mp.Val.V.TtIsNil()); return mp.Val; }
private bool IsFalse(ref TValue v) { if( v.TtIsNil() ) return true; if((v.TtIsBoolean() && v.BValue() == false)) return true; return false; }