[chore] Remove useless table creation
@@ -474,9 +474,8 @@ static int db_prepare(lua_State *L)
int lua_db_release_resource(lua_State *L)
{
- if (luaL_findtable(L, LUA_REGISTRYINDEX, RESOURCE_RS_KEY, 0) != NULL) {
- luaL_error(L, "cannot find the environment of the db module");
- }
+ lua_getfield(L, LUA_REGISTRYINDEX, RESOURCE_RS_KEY);
+ if (lua_istable(L, -1)) {
/* T */
lua_pushnil(L); /* T nil(key) */
while (lua_next(L, -2)) {
@@ -485,10 +484,9 @@ int lua_db_release_resource(lua_State *L)
lua_pop(L, 1);
}
lua_pop(L, 1);
-
- if (luaL_findtable(L, LUA_REGISTRYINDEX, RESOURCE_PSTMT_KEY, 0) != NULL) {
- luaL_error(L, "cannot find the environment of the db module");
}
+ lua_getfield(L, LUA_REGISTRYINDEX, RESOURCE_PSTMT_KEY);
+ if (lua_istable(L, -1)) {
/* T */
lua_pushnil(L); /* T nil(key) */
while (lua_next(L, -2)) {
@@ -497,6 +495,7 @@ int lua_db_release_resource(lua_State *L)
lua_pop(L, 1);
}
lua_pop(L, 1);
+ }
return 0;
}
