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.
|
// Get the classtab from the global environment.
|
||||||
LS.rawget(classtab, globtab, classname);
|
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.
|
// Make a new table if necessary.
|
||||||
if (!LS.rawequal(cname, classname)) {
|
if (!LS.istable(classtab)) {
|
||||||
LS.newtable(classtab);
|
LS.newtable(classtab);
|
||||||
LS.rawset(globtab, classname, classtab);
|
LS.rawset(globtab, classname, classtab);
|
||||||
LS.rawset(classtab, "__class", classname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repair the special fields.
|
// Repair the special fields.
|
||||||
LS.settabletype(classtab, LUA_TT_CLASS);
|
LS.settabletype(classtab, LUA_TT_CLASS);
|
||||||
|
LS.rawset(classtab, "__class", classname);
|
||||||
LS.rawset(classtab, "__index", classtab);
|
LS.rawset(classtab, "__index", classtab);
|
||||||
|
|
||||||
// Put the stack back.
|
// 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 {
|
void LuaStack::cleartable(LuaSlot tab, bool clearmeta) const {
|
||||||
assert(istable(tab));
|
assert(istable(tab));
|
||||||
lua_pushnil(L_);
|
lua_pushnil(L_);
|
||||||
|
|||||||
@@ -371,7 +371,6 @@ public:
|
|||||||
void createtable(LuaSlot target, int narr, int nrec) const;
|
void createtable(LuaSlot target, int narr, int nrec) const;
|
||||||
lua_State *newthread(LuaSlot target) const;
|
lua_State *newthread(LuaSlot target) const;
|
||||||
void getglobaltable(LuaSlot gltab) const;
|
void getglobaltable(LuaSlot gltab) const;
|
||||||
void makesubtable(LuaSlot sub, LuaSlot tab, const char *name) const;
|
|
||||||
void cleartable(LuaSlot tab, bool clearmeta) const;
|
void cleartable(LuaSlot tab, bool clearmeta) const;
|
||||||
|
|
||||||
int rawlen(LuaSlot val) const;
|
int rawlen(LuaSlot val) const;
|
||||||
|
|||||||
@@ -53,22 +53,6 @@ LuaDefine(classname, "classtable", "get the class name from a class table") {
|
|||||||
return LS.result();
|
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) {
|
static void get_reg_name(const LuaFunctionReg *reg, std::string &classname, std::string &funcname) {
|
||||||
std::string name = reg->get_name();
|
std::string name = reg->get_name();
|
||||||
size_t upos = name.find('_');
|
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.
|
// Set up for Lua manipulation.
|
||||||
lua_State *L = state();
|
lua_State *L = state();
|
||||||
LuaVar 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, actions, thread, threads, thinfo, message, invdata);
|
LuaStack LS(L, actor, place, func, tangibles, mt, index, thread, threads, thinfo, message, invdata);
|
||||||
|
|
||||||
// Get the actor and place.
|
// Get the actor and place.
|
||||||
LS.rawget(tangibles, LuaRegistry, "tangibles");
|
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();
|
LS.result();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LS.rawget(actions, index, "action");
|
LS.rawget(func, index, action);
|
||||||
if (!LS.istable(actions)) {
|
|
||||||
LS.result();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
LS.rawget(func, actions, action);
|
|
||||||
if (!LS.isfunction(func)) {
|
if (!LS.isfunction(func)) {
|
||||||
LS.result();
|
LS.result();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -169,7 +169,6 @@ void World::patch_luatabs(StreamBuffer *sb, DebugCollector *dbc) {
|
|||||||
util::HashValue closehash = sb->read_hashvalue();
|
util::HashValue closehash = sb->read_hashvalue();
|
||||||
int ncreate = sb->read_int32();
|
int ncreate = sb->read_int32();
|
||||||
util::IdVector closetans = get_near(actor_id, RadiusClose, true, false);
|
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));
|
assert(closehash == util::hash_id_vector(closetans));
|
||||||
number_lua_tables(closetans);
|
number_lua_tables(closetans);
|
||||||
create_new_tables(ncreate);
|
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) {
|
void World::patch_source(StreamBuffer *sb, DebugCollector *dbc) {
|
||||||
DebugBlock dbb(dbc, "patch_source");
|
DebugBlock dbb(dbc, "patch_source");
|
||||||
std::cerr << "Before PS ids=" << tangible_ids_debug_string() << std::endl;
|
|
||||||
bool modified = source_db_.patch(sb, dbc);
|
bool modified = source_db_.patch(sb, dbc);
|
||||||
if (modified) {
|
if (modified) {
|
||||||
std::string errs = source_db_.rebuild();
|
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
|
// TODO: I don't currently have any good place to send the
|
||||||
// error messages. This is a stopgap.
|
// error messages. This is a stopgap.
|
||||||
std::cerr << errs;
|
std::cerr << errs;
|
||||||
std::cerr << "After PS ids=" << tangible_ids_debug_string() << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
maketangible('login')
|
makeclass('login')
|
||||||
|
|
||||||
function login.interface(actor, place)
|
function login.interface(actor, place)
|
||||||
gui.menu_item("becomeplayer", "Become a Player")
|
gui.menu_item("becomeplayer", "Become a Player")
|
||||||
gui.menu_item("p123", "Print 1, 2, 3")
|
gui.menu_item("p123", "Print 1, 2, 3")
|
||||||
end
|
end
|
||||||
|
|
||||||
function login.action.becomeplayer(actor, place, dialog)
|
function login.becomeplayer(actor, place, dialog)
|
||||||
tangible.setclass(actor, player)
|
tangible.setclass(actor, player)
|
||||||
end
|
end
|
||||||
|
|
||||||
function login.action.p123(actor, place, dialog)
|
function login.p123(actor, place, dialog)
|
||||||
print(1)
|
print(1)
|
||||||
wait(1)
|
wait(1)
|
||||||
print(2)
|
print(2)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
maketangible('player')
|
makeclass('player')
|
||||||
|
|
||||||
function player.interface(actor, place)
|
function player.interface(actor, place)
|
||||||
-- print("actor=", actor)
|
-- print("actor=", actor)
|
||||||
@@ -16,25 +16,25 @@ function player:printanimstate()
|
|||||||
print("Resulting state: ", graphic, plane, x, y, z, facing)
|
print("Resulting state: ", graphic, plane, x, y, z, facing)
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.action.north(actor, place, dialog)
|
function player.north(actor, place, dialog)
|
||||||
print("Moving north")
|
print("Moving north")
|
||||||
tangible.animate(place, {action="walk", dy=1})
|
tangible.animate(place, {action="walk", dy=1})
|
||||||
actor:printanimstate()
|
actor:printanimstate()
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.action.south(actor, place, dialog)
|
function player.south(actor, place, dialog)
|
||||||
print("Moving south")
|
print("Moving south")
|
||||||
tangible.animate(place, {action="walk", dy=-1})
|
tangible.animate(place, {action="walk", dy=-1})
|
||||||
actor:printanimstate()
|
actor:printanimstate()
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.action.east(actor, place, dialog)
|
function player.east(actor, place, dialog)
|
||||||
print("Moving east")
|
print("Moving east")
|
||||||
tangible.animate(place, {action="walk", dx=1})
|
tangible.animate(place, {action="walk", dx=1})
|
||||||
actor:printanimstate()
|
actor:printanimstate()
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.action.west(actor, place, dialog)
|
function player.west(actor, place, dialog)
|
||||||
print("Moving west")
|
print("Moving west")
|
||||||
tangible.animate(place, {action="walk", dx=-1})
|
tangible.animate(place, {action="walk", dx=-1})
|
||||||
actor:printanimstate()
|
actor:printanimstate()
|
||||||
|
|||||||
Reference in New Issue
Block a user