Implement tabletype tagging
This commit is contained in:
@@ -38,8 +38,8 @@ World::World(util::WorldType wt) {
|
||||
}
|
||||
|
||||
// Prepare to manipulate the lua state.
|
||||
LuaVar world;
|
||||
LuaStack LS(state(), world);
|
||||
LuaVar world, globtab;
|
||||
LuaStack LS(state(), world, globtab);
|
||||
|
||||
// Put the world pointer into the lua registry.
|
||||
World::store_global_pointer(state(), this);
|
||||
@@ -47,6 +47,13 @@ World::World(util::WorldType wt) {
|
||||
// Clear the global GUI pointer.
|
||||
Gui::store_global_pointer(state(), nullptr);
|
||||
|
||||
// Set the tabletype of the registry.
|
||||
LS.settabletype(LuaRegistry, LuaStack::TAB_REGISTRY);
|
||||
|
||||
// Set the tabletype of the global environment.
|
||||
LS.getglobaltable(globtab);
|
||||
LS.settabletype(globtab, LuaStack::TAB_GLOBALENV);
|
||||
|
||||
// Create the tangibles table in the registry.
|
||||
LS.rawset(LuaRegistry, "tangibles", LuaNewTable);
|
||||
|
||||
@@ -230,6 +237,10 @@ Tangible *World::tangible_make(lua_State *L, int64_t id, bool pushdb) {
|
||||
LS.set(metatab, LuaNewTable);
|
||||
LS.setmetatable(database, metatab);
|
||||
|
||||
// Mark the tangible using the tabletype field.
|
||||
LS.settabletype(database, LuaStack::TAB_TANGIBLE);
|
||||
LS.settabletype(metatab, LuaStack::TAB_TANGIBLEMETA);
|
||||
|
||||
// Store the database into the tangibles table.
|
||||
LS.rawget(tangibles, LuaRegistry, "tangibles");
|
||||
LS.rawset(tangibles, id, database);
|
||||
@@ -857,6 +868,33 @@ LuaDefine(world_getregistry, "f") {
|
||||
return 1;
|
||||
}
|
||||
|
||||
LuaDefine(world_gettabletype, "f") {
|
||||
LuaArg tab;
|
||||
LuaRet ttype;
|
||||
LuaStack LS(L, tab, ttype);
|
||||
if (LS.istable(tab)) {
|
||||
LuaStack::TableType tt = LS.gettabletype(tab);
|
||||
LS.set(ttype, int(tt));
|
||||
} else {
|
||||
luaL_error(L, "Not a table");
|
||||
}
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
LuaDefine(world_settabletype, "f") {
|
||||
LuaArg tab, ttype;
|
||||
LuaStack LS(L, tab, ttype);
|
||||
if (!LS.istable(tab)) {
|
||||
luaL_error(L, "Not a table");
|
||||
}
|
||||
int tt = LS.ckinteger(ttype);
|
||||
if ((tt < 0) || (tt > 15)) {
|
||||
luaL_error(L, "table type out of range");
|
||||
}
|
||||
LS.settabletype(tab, LuaStack::TableType(tt));
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
static bool worlds_identical(const std::unique_ptr<World> &w1, const std::unique_ptr<World> &w2) {
|
||||
StreamBuffer sbw1, sbw2;
|
||||
w1->serialize(&sbw1);
|
||||
|
||||
Reference in New Issue
Block a user