Lots of work on documenting class LuaStack

This commit is contained in:
2024-03-20 14:29:20 -04:00
parent 3d6b5224f3
commit bb83837377
7 changed files with 981 additions and 479 deletions

View File

@@ -88,6 +88,9 @@ lua_State *LuaCoreStack::newstate (lua_Alloc allocf) {
lua_pushstring(L, "tangibles");
lua_newtable(L);
lua_rawset(L, LUA_REGISTRYINDEX);
lua_pushstring(L, "worldtype");
lua_pushnumber(L, WORLD_TYPE_MASTER);
lua_rawset(L, LUA_REGISTRYINDEX);
return L;
}
@@ -299,14 +302,14 @@ bool LuaCoreStack::getmetatable(LuaSlot mt, LuaSlot tab) const {
}
}
int LuaCoreStack::next(LuaSlot tab, LuaSlot key, LuaSlot value) const {
bool LuaCoreStack::next(LuaSlot tab, LuaSlot key, LuaSlot value) const {
lua_pushvalue(L_, key);
int ret = lua_next(L_, tab);
if (ret != 0) {
lua_replace(L_, value);
lua_replace(L_, key);
}
return ret;
return (ret != 0);
}
void LuaCoreStack::getglobaltable(LuaSlot target) const {
@@ -334,14 +337,6 @@ bool LuaCoreStack::valididentifier(std::string_view str) {
return sv::is_lua_id(str);
}
bool LuaCoreStack::validint64(int64_t value) {
return (value <= MAXINT) && (value >= -MAXINT);
}
bool LuaCoreStack::validpositiveint64(int64_t value) {
return (value <= MAXINT) && (value >= 1);
}
bool LuaCoreStack::validclassname(std::string_view cname) {
if (cname == "_G") return false;
return valididentifier(cname);
@@ -473,7 +468,7 @@ void LuaCoreStack::makeclass(LuaSlot tab, std::string_view name) const {
}
void LuaCoreStack::maketan(LuaSlot tab, int64_t id) const {
assert(validpositiveint64(id));
assert(validpositiveinteger(id));
LuaVar tangibles, metatab;
LuaExtStack LS(L_, tangibles, metatab);
@@ -627,7 +622,7 @@ void LuaCoreStack::setvisited(LuaSlot tab, bool visited) const {
lua_modflagbits(L_, tab.index(), 0x0010, visited ? 0x0010 : 0);
}
WorldType LuaCoreStack::world_type() const {
WorldType LuaCoreStack::get_world_type() const {
lua_pushstring(L_, "worldtype");
lua_rawget(L_, LUA_REGISTRYINDEX);
lua_Integer n = lua_tointeger(L_, -1);
@@ -636,6 +631,12 @@ WorldType LuaCoreStack::world_type() const {
return (WorldType)n;
}
void LuaCoreStack::set_world_type(WorldType t) const {
lua_pushstring(L_, "worldtype");
lua_pushnumber(L_, (int)t);
lua_rawset(L_, LUA_REGISTRYINDEX);
}
void LuaCoreStack::guard_nopredict(const char *fn) {
if (lua_isyieldable(L_)) {
if (!is_authoritative()) {