Remove more invalid uses of luaL_error and luaL_check

This commit is contained in:
2021-12-27 17:03:42 -05:00
parent 9517b3e004
commit 0c021dc93a
3 changed files with 24 additions and 58 deletions

View File

@@ -34,10 +34,6 @@ const LuaFunctionReg *LuaFunctionReg::lookup(lua_CFunction fn) {
LuaFunctionReg *LuaFunctionReg::LuaFunctionRegistry;
bool LuaStack::issortablekey(LuaSlot s) const {
int type = lua_type(L_, s);
return (type == LUA_TBOOLEAN) || (type == LUA_TNUMBER) || (type == LUA_TSTRING);
}
bool LuaStack::ckboolean(LuaSlot s) const {
luaL_checktype(L_, s, LUA_TBOOLEAN);
@@ -106,27 +102,6 @@ int LuaStack::result() {
return nret_;
}
void LuaStack::pop_any_value(lua_Integer &s) const {
luaL_checktype(L_, -1, LUA_TNUMBER);
s = lua_tointeger(L_, -1);
lua_pop(L_, 1);
}
void LuaStack::pop_any_value(lua_Number &s) const {
luaL_checktype(L_, -1, LUA_TNUMBER);
s = lua_tonumber(L_, -1);
lua_pop(L_, 1);
}
void LuaStack::pop_any_value(std::string &s) const {
luaL_checktype(L_, -1, LUA_TSTRING);
size_t len;
const char *str = lua_tolstring(L_, -1, &len);
s = std::string(str, len);
lua_pop(L_, 1);
}
void LuaStack::clearmetatable(LuaSlot tab) const {
lua_pushnil(L_);
lua_setmetatable(L_, tab);
@@ -148,15 +123,6 @@ bool LuaStack::getmetatable(LuaSlot mt, LuaSlot tab) const {
}
}
void LuaStack::checknometa(LuaSlot index) const {
if (lua_istable(L_, index)) {
if (!lua_getmetatable(L_, index)) {
return;
}
}
luaL_error(L_, "expected simple table with no metatable");
}
int LuaStack::next(LuaSlot tab, LuaSlot key, LuaSlot value) const {
lua_pushvalue(L_, key);
int ret = lua_next(L_, tab);
@@ -359,6 +325,10 @@ int64_t LuaStack::tanid(LuaSlot tab) const {
return result;
}
bool LuaStack::issortablekey(LuaSlot s) const {
int type = lua_type(L_, s);
return (type == LUA_TBOOLEAN) || (type == LUA_TNUMBER) || (type == LUA_TSTRING);
}
void LuaStack::movesortablekey(LuaSlot key, LuaStack &otherstack, LuaSlot otherslot) {
int type = lua_type(L_, key);
@@ -379,25 +349,23 @@ void LuaStack::movesortablekey(LuaSlot key, LuaStack &otherstack, LuaSlot others
break;
}
default:
luaL_error(L_, "movesortablekey: not a sortable key");
assert(false && "movesortablekey: not a sortable key");
}
}
void LuaStack::makesubtable(LuaSlot sub, LuaSlot tab, const char *name) const {
assert(istable(tab));
rawget(sub, tab, name);
if (istable(sub)) {
return;
} else if (isnil(sub)) {
} else {
newtable(sub);
rawset(tab, name, sub);
return;
} else {
luaL_error(L_, "%s is not a table", name);
}
}
void LuaStack::cleartable(LuaSlot tab, bool clearmeta) const {
checktable(tab);
assert(istable(tab));
lua_pushnil(L_);
while (lua_next(L_, tab.index()) != 0) {
lua_pop(L_, 1); // Pop the old value.