Exemplo n.º 1
0
        private bool Eq(LuaValue a, LuaValue b, LuaState ls)
        {
            if (a.IsNil())
            {
                return(b.IsNil());
            }
            else if (a.IsBool())
            {
                return(b.IsBool() && a.GetBoolValue() == b.GetBoolValue());
            }
            else if (a.IsString())
            {
                return(b.IsString() && a.GetStrValue() == b.GetStrValue());
            }
            else if (a.IsInt())
            {
                if (b.IsInt())
                {
                    return(a.GetIntValue() == b.GetIntValue());
                }
                else if (b.IsFloat())
                {
                    return(a.GetIntValue() == b.GetFloatValue());
                }
                else
                {
                    return(false);
                }
            }
            else if (a.IsFloat())
            {
                if (b.IsFloat())
                {
                    return(a.GetFloatValue() == b.GetFloatValue());
                }
                else if (b.IsInt())
                {
                    return(a.GetFloatValue() == b.GetIntValue());
                }
                else
                {
                    return(false);
                }
            }
            else if (a.IsTable() &&
                     b.IsTable() &&
                     a.GetTableValue() != b.GetTableValue() && ls != null)
            {
                if (LuaValue.CallMetaMethod(a, b, "__eq", ls, out var metaMethodRet))
                {
                    return(metaMethodRet.ToBoolean());
                }

                return(a.GetValue() == b.GetValue());
            }
            else
            {
                return(a.GetValue() == b.GetValue());
            }
        }