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()); } }
private bool Lt(LuaValue a, LuaValue b, LuaState ls) { if (a.IsString()) { return(b.IsString() && string.Compare(a.GetStrValue(), b.GetStrValue(), StringComparison.Ordinal) < 0); } else if (a.IsNumber() && b.IsNumber()) { return(a.GetFloatValue() < b.GetFloatValue()); } if (LuaValue.CallMetaMethod(a, b, "__lt", ls, out var metaMethodRet)) { return(metaMethodRet.ToBoolean()); } Debug.Panic("comparison error!"); return(false); }