Esempio n. 1
0
        public StkId Get(ref TValue key)
        {
            if (key.Tt == (int)LuaType.LUA_TNIL)
            {
                return(TheNilValue);
            }

            if (IsPositiveInteger(ref key))
            {
                return(GetInt((int)key.NValue));
            }

            if (key.Tt == (int)LuaType.LUA_TSTRING)
            {
                return(GetStr(key.SValue()));
            }

            var h = key.GetHashCode();

            for (var node = GetHashNode(h); node != null; node = node.Next)
            {
                if (node.Key.V == key)
                {
                    { return(node.Val); }
                }
            }

            return(TheNilValue);
        }
Esempio n. 2
0
        public bool Equals(TValue o)
        {
            if (Tt != o.Tt || NValue != o.NValue || UInt64Value != o.UInt64Value)
            {
                return(false);
            }

            switch (Tt)
            {
            case (int)LuaType.LUA_TNIL: return(true);

            case (int)LuaType.LUA_TBOOLEAN: return(BValue() == o.BValue());

            case (int)LuaType.LUA_TNUMBER: return(NValue == o.NValue);

            case (int)LuaType.LUA_TUINT64: return(UInt64Value == o.UInt64Value);

            case (int)LuaType.LUA_TSTRING: return(SValue() == o.SValue());

            //!ADD BY hyf042
            case (int)LuaType.LUA_TLIGHTUSERDATA:
                return(System.Object.ReferenceEquals(OValue, o.OValue));

            default: return(System.Object.ReferenceEquals(OValue, o.OValue));
            }
        }
Esempio n. 3
0
        public bool Equals(TValue o)
        {
            if(Tt != o.Tt || NValue != o.NValue || UInt64Value != o.UInt64Value)
                { return false; }

            switch(Tt) {
                case (int)LuaType.LUA_TNIL: return true;
                case (int)LuaType.LUA_TBOOLEAN: return BValue() == o.BValue();
                case (int)LuaType.LUA_TNUMBER: return NValue == o.NValue;
                case (int)LuaType.LUA_TUINT64: return UInt64Value == o.UInt64Value;
                case (int)LuaType.LUA_TSTRING: return SValue() == o.SValue();
                default: return System.Object.ReferenceEquals(OValue, o.OValue);
            }
        }
Esempio n. 4
0
        private HNode GetHashNode(ref TValue v)
        {
            if (IsPositiveInteger(ref v))
            {
                return(GetHashNode((int)v.NValue));
            }

            if (v.TtIsString())
            {
                return(GetHashNode(v.SValue().GetHashCode()));
            }

            return(GetHashNode(v.GetHashCode()));
        }
Esempio n. 5
0
        public override string ToString()
        {
            string detail;

            if (V.TtIsString())
            {
                detail = V.SValue().Replace("\n", "»");
            }
            else
            {
                detail = "...";
            }
            return(string.Format("StkId - {0} - {1}", LuaState.TypeName((LuaType)V.Tt), detail));
        }
Esempio n. 6
0
        public bool Equals(TValue o)
        {
            if(Tt != o.Tt || NValue != o.NValue)
                { return false; }

            switch(Tt) {
                case (int)LuaType.LUA_TNIL:
                    return true;
                case (int)LuaType.LUA_TSTRING:
                    return SValue() == o.SValue();
                default:
                    return System.Object.ReferenceEquals(OValue, o.OValue);
            }
        }
Esempio n. 7
0
		public StkId Get(ref TValue key)
		{
			if(key.Tt == (int)LuaType.LUA_TNIL) { return TheNilValue; }

			if(IsPositiveInteger(ref key))
				{ return GetInt((int)key.NValue); }

			if(key.Tt == (int)LuaType.LUA_TSTRING)
				{ return GetStr(key.SValue()); }

			var h = key.GetHashCode();
			for(var node = GetHashNode(h); node != null; node = node.Next) {
				if(node.Key.V == key) {
					{ return node.Val; }
				}
			}

			return TheNilValue;
		}
Esempio n. 8
0
        private bool V_EqualObject(ref TValue t1, ref TValue t2, bool rawEq)
        {
            Utl.Assert(t1.Tt == t2.Tt);
            StkId tm = null;

            switch (t1.Tt)
            {
            case (int)LuaType.LUA_TNIL:
                return(true);

            case (int)LuaType.LUA_TNUMBER:
                return(t1.NValue == t2.NValue);

            case (int)LuaType.LUA_TUINT64:
                return(t1.UInt64Value == t2.UInt64Value);

            case (int)LuaType.LUA_TBOOLEAN:
                return(t1.BValue() == t2.BValue());

            case (int)LuaType.LUA_TSTRING:
                return(t1.SValue() == t2.SValue());

            case (int)LuaType.LUA_TUSERDATA:
            {
                var ud1 = t1.RawUValue();
                var ud2 = t2.RawUValue();
                if (ud1.Value == ud2.Value)
                {
                    return(true);
                }
                if (rawEq)
                {
                    return(false);
                }
                tm = GetEqualTM(ud1.MetaTable, ud2.MetaTable, TMS.TM_EQ);
                break;
            }

            case (int)LuaType.LUA_TTABLE:
            {
                var tbl1 = t1.HValue();
                var tbl2 = t2.HValue();
                if (System.Object.ReferenceEquals(tbl1, tbl2))
                {
                    return(true);
                }
                if (rawEq)
                {
                    return(false);
                }
                tm = GetEqualTM(tbl1.MetaTable, tbl2.MetaTable, TMS.TM_EQ);
                break;
            }

            default:
                return(t1.OValue == t2.OValue);
            }
            if (tm == null)              // no TM?
            {
                return(false);
            }
            CallTM(ref tm.V, ref t1, ref t2, Top, true);              // call TM
            return(!IsFalse(ref Top.V));
        }
Esempio n. 9
0
        private HNode GetHashNode(ref TValue v)
        {
            if(IsPositiveInteger(ref v)) { return GetHashNode((int)v.NValue); }

            if(v.TtIsString()) { return GetHashNode(v.SValue().GetHashCode()); }

            return GetHashNode(v.GetHashCode());
        }
Esempio n. 10
0
		private bool V_EqualObject( ref TValue t1, ref TValue t2, bool rawEq )
		{
			Utl.Assert( t1.Tt == t2.Tt );
			StkId tm = null;
			switch( t1.Tt )
			{
				case (int)LuaType.LUA_TNIL:
					return true;
				case (int)LuaType.LUA_TNUMBER:
					return t1.NValue == t2.NValue;
				case (int)LuaType.LUA_TUINT64:
					return t1.UInt64Value == t2.UInt64Value;
				case (int)LuaType.LUA_TBOOLEAN:
					return t1.BValue() == t2.BValue();
				case (int)LuaType.LUA_TSTRING:
					return t1.SValue() == t2.SValue();
				case (int)LuaType.LUA_TUSERDATA:
				{
					var ud1 = t1.RawUValue();
					var ud2 = t2.RawUValue();
					if(ud1.Value == ud2.Value)
						return true;
					if(rawEq)
						return false;
					tm = GetEqualTM( ud1.MetaTable, ud2.MetaTable, TMS.TM_EQ );
					break;
				}
				case (int)LuaType.LUA_TTABLE:
				{
					var tbl1 = t1.HValue();
					var tbl2 = t2.HValue();
					if( System.Object.ReferenceEquals( tbl1, tbl2 ) )
						return true;
					if( rawEq )
						return false;
					tm = GetEqualTM( tbl1.MetaTable, tbl2.MetaTable, TMS.TM_EQ );
					break;
				}
				default:
					return t1.OValue == t2.OValue;
			}
			if( tm == null ) // no TM?
				return false;
			CallTM(ref tm.V, ref t1, ref t2, Top, true ); // call TM
			return !IsFalse(ref Top.V);
		}