Eliminate LuaStack::rawgeti, it's not safe

This commit is contained in:
2021-11-17 15:11:55 -05:00
parent fb043e9971
commit 0881e33c6f
5 changed files with 32 additions and 32 deletions

View File

@@ -45,7 +45,7 @@ std::string World::tangible_pprint(int64_t id) const {
LuaVar tangibles, tan, meta;
LuaStack LS(L, tangibles, tan, meta);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawgeti(tan, tangibles, id);
LS.rawget(tan, tangibles, id);
std::ostringstream oss;
if (LS.istable(tan)) {
LS.getmetatable(meta, tan);
@@ -72,7 +72,7 @@ std::string World::numbered_tables_debug_string() const {
// Iterate over the map. For each table, if it has
// a TID, output that. Otherwise, output "unknown".
for (int i = 1; i < 10000; i++) {
LS.rawgeti(tab, ntmap, i);
LS.rawget(tab, ntmap, i);
if (!LS.istable(tab)) break;
LS.rawget(tid, tab, "TID");
if (LS.isstring(tid)) {
@@ -201,7 +201,7 @@ void World::tangible_set_class(int64_t id, const std::string &c) const {
LuaVar tangibles, tan, meta, sclass;
LuaStack LS(state(), tangibles, tan, meta, sclass);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawgeti(tan, tangibles, id);
LS.rawget(tan, tangibles, id);
assert(LS.istable(tan));
LS.getmetatable(meta, tan);
if (c == "") {
@@ -217,7 +217,7 @@ std::string World::tangible_get_class(int64_t id) const {
LuaVar tangibles, tan, meta, sclass;
LuaStack LS(state(), tangibles, tan, meta, sclass);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawgeti(tan, tangibles, id);
LS.rawget(tan, tangibles, id);
assert(LS.istable(tan));
LS.getmetatable(meta, tan);
LS.rawget(sclass, meta, "__index");