Remove action subtable, fix bug in makeclass
This commit is contained in:
@@ -273,22 +273,15 @@ void LuaStack::makeclass(LuaSlot classtab, LuaSlot classname) const {
|
||||
// Get the classtab from the global environment.
|
||||
LS.rawget(classtab, globtab, classname);
|
||||
|
||||
// Make sure we're not reusing a table that isn't a class.
|
||||
if (LS.istable(classtab)) {
|
||||
LS.rawget(cname, classtab, "__class");
|
||||
} else {
|
||||
LS.set(cname, LuaNil);
|
||||
}
|
||||
|
||||
// Make a new table if necessary.
|
||||
if (!LS.rawequal(cname, classname)) {
|
||||
if (!LS.istable(classtab)) {
|
||||
LS.newtable(classtab);
|
||||
LS.rawset(globtab, classname, classtab);
|
||||
LS.rawset(classtab, "__class", classname);
|
||||
}
|
||||
|
||||
// Repair the special fields.
|
||||
LS.settabletype(classtab, LUA_TT_CLASS);
|
||||
LS.rawset(classtab, "__class", classname);
|
||||
LS.rawset(classtab, "__index", classtab);
|
||||
|
||||
// Put the stack back.
|
||||
@@ -353,17 +346,6 @@ void LuaStack::movesortablekey(LuaSlot key, LuaStack &otherstack, LuaSlot others
|
||||
}
|
||||
}
|
||||
|
||||
void LuaStack::makesubtable(LuaSlot sub, LuaSlot tab, const char *name) const {
|
||||
assert(istable(tab));
|
||||
rawget(sub, tab, name);
|
||||
if (istable(sub)) {
|
||||
return;
|
||||
} else {
|
||||
newtable(sub);
|
||||
rawset(tab, name, sub);
|
||||
}
|
||||
}
|
||||
|
||||
void LuaStack::cleartable(LuaSlot tab, bool clearmeta) const {
|
||||
assert(istable(tab));
|
||||
lua_pushnil(L_);
|
||||
|
||||
@@ -371,7 +371,6 @@ public:
|
||||
void createtable(LuaSlot target, int narr, int nrec) const;
|
||||
lua_State *newthread(LuaSlot target) const;
|
||||
void getglobaltable(LuaSlot gltab) const;
|
||||
void makesubtable(LuaSlot sub, LuaSlot tab, const char *name) const;
|
||||
void cleartable(LuaSlot tab, bool clearmeta) const;
|
||||
|
||||
int rawlen(LuaSlot val) const;
|
||||
|
||||
@@ -53,22 +53,6 @@ LuaDefine(classname, "classtable", "get the class name from a class table") {
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
LuaDefine(maketangible, "classname", "create a class if it doesn't already exist, and add tangible features") {
|
||||
LuaArg classname;
|
||||
LuaRet classtab;
|
||||
LuaVar subtab;
|
||||
LuaStack LS(L, classname, classtab, subtab);
|
||||
if (!LS.isstring(classname)) {
|
||||
luaL_error(L, "class name must be a string");
|
||||
}
|
||||
if (!LS.validclassname(classname)) {
|
||||
luaL_error(L, "invalid class name: %s", LS.ckstring(classname).c_str());
|
||||
};
|
||||
LS.makeclass(classtab, classname);
|
||||
LS.makesubtable(subtab, classtab, "action");
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
static void get_reg_name(const LuaFunctionReg *reg, std::string &classname, std::string &funcname) {
|
||||
std::string name = reg->get_name();
|
||||
size_t upos = name.find('_');
|
||||
|
||||
@@ -542,8 +542,8 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a
|
||||
|
||||
// Set up for Lua manipulation.
|
||||
lua_State *L = state();
|
||||
LuaVar actor, place, func, tangibles, mt, index, actions, thread, threads, thinfo, message, invdata;
|
||||
LuaStack LS(L, actor, place, func, tangibles, mt, index, actions, thread, threads, thinfo, message, invdata);
|
||||
LuaVar actor, place, func, tangibles, mt, index, thread, threads, thinfo, message, invdata;
|
||||
LuaStack LS(L, actor, place, func, tangibles, mt, index, thread, threads, thinfo, message, invdata);
|
||||
|
||||
// Get the actor and place.
|
||||
LS.rawget(tangibles, LuaRegistry, "tangibles");
|
||||
@@ -565,12 +565,7 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
LS.rawget(actions, index, "action");
|
||||
if (!LS.istable(actions)) {
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
LS.rawget(func, actions, action);
|
||||
LS.rawget(func, index, action);
|
||||
if (!LS.isfunction(func)) {
|
||||
LS.result();
|
||||
return;
|
||||
|
||||
@@ -169,7 +169,6 @@ void World::patch_luatabs(StreamBuffer *sb, DebugCollector *dbc) {
|
||||
util::HashValue closehash = sb->read_hashvalue();
|
||||
int ncreate = sb->read_int32();
|
||||
util::IdVector closetans = get_near(actor_id, RadiusClose, true, false);
|
||||
std::cerr << "Sync closetans=" << util::id_vector_debug_string(closetans) << std::endl;
|
||||
assert(closehash == util::hash_id_vector(closetans));
|
||||
number_lua_tables(closetans);
|
||||
create_new_tables(ncreate);
|
||||
@@ -283,7 +282,6 @@ void World::diff_tanclass(int64_t actor_id, World *master, StreamBuffer *xsb) {
|
||||
|
||||
void World::patch_source(StreamBuffer *sb, DebugCollector *dbc) {
|
||||
DebugBlock dbb(dbc, "patch_source");
|
||||
std::cerr << "Before PS ids=" << tangible_ids_debug_string() << std::endl;
|
||||
bool modified = source_db_.patch(sb, dbc);
|
||||
if (modified) {
|
||||
std::string errs = source_db_.rebuild();
|
||||
@@ -291,7 +289,6 @@ void World::patch_source(StreamBuffer *sb, DebugCollector *dbc) {
|
||||
// TODO: I don't currently have any good place to send the
|
||||
// error messages. This is a stopgap.
|
||||
std::cerr << errs;
|
||||
std::cerr << "After PS ids=" << tangible_ids_debug_string() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user