Numbering and pairing of lua tables

This commit is contained in:
2021-08-13 17:02:35 -04:00
parent ee16970a8a
commit 7581ac7278
7 changed files with 504 additions and 7 deletions

View File

@@ -23,6 +23,11 @@ LuaFunctionReg::List LuaFunctionReg::all() {
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);
return lua_toboolean(L_, s) ? true:false;
@@ -121,9 +126,15 @@ void LuaStack::setmetatable(LuaSlot tab, LuaSlot mt) const {
lua_setmetatable(L_, tab);
}
void LuaStack::getmetatable(LuaSlot mt, LuaSlot tab) const {
lua_getmetatable(L_, tab);
lua_replace(L_, mt);
bool LuaStack::getmetatable(LuaSlot mt, LuaSlot tab) const {
if (lua_getmetatable(L_, tab)) {
lua_replace(L_, mt);
return true;
} else {
lua_pushnil(L_);
lua_replace(L_, mt);
return false;
}
}
void LuaStack::checknometa(LuaSlot index) const {
@@ -231,6 +242,26 @@ void LuaStack::makeclass(LuaSlot classtab, LuaSlot classname) const {
LS.result();
}
void LuaStack::movesortablekey(LuaSlot key, lua_State *L) {
int type = lua_type(L_, key);
switch (type) {
case LUA_TBOOLEAN:
lua_pushboolean(L, lua_toboolean(L_, key));
break;
case LUA_TNUMBER:
lua_pushnumber(L, lua_tonumber(L_, key));
break;
case LUA_TSTRING: {
size_t len;
const char *str = lua_tolstring(L_, key, &len);
lua_pushlstring(L, str, len);
break;
}
default:
luaL_error(L, "movesortablekey: not a sortable key");
}
}
void LuaStack::makesubtable(LuaSlot sub, LuaSlot tab, const char *name) const {
rawget(sub, tab, name);
if (istable(sub)) {