Get rid of getfield/setfield

This commit is contained in:
2021-02-10 16:47:45 -05:00
parent 3883f86dee
commit eefe1bd58a
5 changed files with 63 additions and 61 deletions

View File

@@ -27,10 +27,10 @@ World::World() {
// Put the world pointer into the lua registry.
LS.newpointer(world, this, false);
LS.setfield(LuaRegistry, "world", world);
LS.rawset(LuaRegistry, "world", world);
// Create the tangibles table in the registry.
LS.setfield(LuaRegistry, "tangibles", LuaNewTable);
LS.rawset(LuaRegistry, "tangibles", LuaNewTable);
// Initialize the SourceDB
source_db_.initialize(state());
@@ -51,10 +51,10 @@ void Tangible::be_a_player() {
LuaStack LS(world_->state(), classtab, mt, place, tangibles);
LS.makeclass(classtab, "player");
LS.getfield(tangibles, LuaRegistry, "tangibles");
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(place, tangibles, anim_queue_.get_id());
LS.getmetatable(mt, place);
LS.setfield(mt, "__index", classtab);
LS.rawset(mt, "__index", classtab);
LS.result();
}
}
@@ -113,14 +113,14 @@ Tangible *World::tangible_make(lua_State *L, int64_t id, bool pushdb) {
LS.setmetatable(database, metatab);
// Store the database into the tangibles table.
LS.getfield(tangibles, LuaRegistry, "tangibles");
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawset(tangibles, id, database);
// Populate the database and metatable with initial stuff.
LS.setfield(database, "inventory", LuaNewTable);
LS.setfield(database, "id", id);
LS.setfield(metatab, "id", id);
// LS.setfield(metatab, "__metatable", LuaNil);
LS.rawset(database, "inventory", LuaNewTable);
LS.rawset(database, "id", id);
LS.rawset(metatab, "id", id);
// LS.rawset(metatab, "__metatable", LuaNil);
LS.result();
if (!pushdb) lua_pop(L, 1);
@@ -130,7 +130,7 @@ Tangible *World::tangible_make(lua_State *L, int64_t id, bool pushdb) {
World *World::fetch(lua_State *L) {
LuaVar world;
LuaStack LS(L, world);
LS.getfield(world, LuaRegistry, "world");
LS.rawget(world, LuaRegistry, "world");
World *w = LS.ckuserdata<World>(world);
LS.result();
return w;
@@ -144,7 +144,7 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
LuaStack LS(L, actor, place, ugui, func, tangibles);
// Get the actor and place.
LS.getfield(tangibles, LuaRegistry, "tangibles");
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(actor, tangibles, actor_id);
LS.rawget(place, tangibles, place_id);
if (!LS.istable(actor) || !LS.istable(place)) {
@@ -153,7 +153,8 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
}
// Get the interface closure.
LS.getfield(func, place, "interface");
// Use of 'gettable' instead of 'rawget' is deliberate.
LS.gettable(func, place, "interface");
if (!LS.isfunction(func)) {
LS.result();
return;
@@ -188,7 +189,7 @@ LuaDefine(tangible_get, "c") {
LuaVar tangibles;
LuaStack LS(L, id, database, tangibles);
LS.getfield(tangibles, LuaRegistry, "tangibles");
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(database, tangibles, id);
return LS.result();
}