Overhaul tangible_make to get rid of LuaOldStack
This commit is contained in:
@@ -43,7 +43,7 @@ World::World(WorldType wt) {
|
||||
|
||||
// Prepare to manipulate the lua state.
|
||||
LuaVar world, globtab;
|
||||
LuaOldStack LS(state(), world, globtab);
|
||||
LuaExtStack LS(state(), world, globtab);
|
||||
|
||||
// Put the world pointer into the lua registry.
|
||||
World::store_global_pointer(state(), this);
|
||||
@@ -75,9 +75,6 @@ World::World(WorldType wt) {
|
||||
|
||||
// Initialize global variable state.
|
||||
assign_seqno_ = 1;
|
||||
|
||||
LS.result();
|
||||
assert (stack_is_clear());
|
||||
}
|
||||
|
||||
Tangible::Tangible(World *w, int64_t id) : world_(w), anim_queue_(w->world_type_), id_player_pool_(&w->id_global_pool_) {
|
||||
@@ -143,17 +140,10 @@ Tangible *World::tangible_get(const LuaCoreStack &LS, LuaSlot tab, bool allowdel
|
||||
return result;
|
||||
}
|
||||
|
||||
Tangible *World::tangible_make(lua_State *L, int64_t id, const eng::string &plane, bool pushdb) {
|
||||
// Get a state if we don't already have one.
|
||||
if (L == nullptr) {
|
||||
L = state();
|
||||
assert(!pushdb);
|
||||
}
|
||||
Tangible *World::tangible_make(const LuaCoreStack &LS0, LuaSlot database, int64_t id, const eng::string &plane) {
|
||||
assert(id != 0);
|
||||
|
||||
LuaVar metatab;
|
||||
LuaRet database;
|
||||
LuaOldStack LS(L, database, metatab);
|
||||
LuaExtStack LS(LS0.state(), metatab);
|
||||
|
||||
// Create the C++ part of the structure.
|
||||
UniqueTangible &t = tangibles_[id];
|
||||
@@ -171,21 +161,24 @@ Tangible *World::tangible_make(lua_State *L, int64_t id, const eng::string &plan
|
||||
// Set up the inventory and thread table.
|
||||
LS.rawset(database, "inventory", LuaNewTable);
|
||||
LS.rawset(metatab, "threads", LuaNewTable);
|
||||
|
||||
LS.result();
|
||||
if (!pushdb) lua_pop(L, 1);
|
||||
|
||||
return t.get();
|
||||
}
|
||||
|
||||
Tangible *World::tangible_make(int64_t id, const eng::string &plane) {
|
||||
LuaVar database;
|
||||
LuaExtStack LS(state(), database);
|
||||
return tangible_make(LS, database, id, plane);
|
||||
}
|
||||
|
||||
void World::tangible_delete(int64_t id) {
|
||||
lua_State *L = state();
|
||||
LuaVar tangibles, database, metatab;
|
||||
LuaOldStack LS(L, tangibles, database, metatab);
|
||||
LuaExtStack LS(L, tangibles, database, metatab);
|
||||
|
||||
// Fetch the C++ side of the tangible.
|
||||
auto iter = tangibles_.find(id);
|
||||
if (iter == tangibles_.end()) {
|
||||
LS.result();
|
||||
return; // Nothing to delete.
|
||||
}
|
||||
|
||||
@@ -204,7 +197,6 @@ void World::tangible_delete(int64_t id) {
|
||||
|
||||
// Remove the C++ portion from the tangibles table.
|
||||
tangibles_.erase(iter);
|
||||
LS.result();
|
||||
}
|
||||
|
||||
util::IdVector World::get_near(int64_t player_id, float radius, bool exclude_nowhere, bool omit_player, bool sorted) const {
|
||||
@@ -235,17 +227,14 @@ World::Redirects World::fetch_redirects() {
|
||||
int64_t World::create_login_actor() {
|
||||
assert(stack_is_clear());
|
||||
int64_t id = id_global_pool_.get_one();
|
||||
Tangible *tan = tangible_make(state(), id, "nowhere", true);
|
||||
LuaArg database;
|
||||
LuaVar classtab, mt;
|
||||
LuaOldStack LS(state(), database, classtab, mt);
|
||||
LuaVar database, classtab, mt;
|
||||
LuaExtStack LS(state(), database, classtab, mt);
|
||||
Tangible *tan = tangible_make(LS, database, id, "nowhere");
|
||||
LS.makeclass(classtab, "login");
|
||||
LS.getmetatable(mt, database);
|
||||
LS.rawset(mt, "__index", classtab);
|
||||
LS.result();
|
||||
tan->configure_id_pool_for_actor();
|
||||
tan->print_buffer_.clear();
|
||||
assert(stack_is_clear());
|
||||
return tan->id();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user