diff --git a/luprex/core/cpp/luastack.cpp b/luprex/core/cpp/luastack.cpp index 72c0d2c1..2040f5e7 100644 --- a/luprex/core/cpp/luastack.cpp +++ b/luprex/core/cpp/luastack.cpp @@ -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_); diff --git a/luprex/core/cpp/luastack.hpp b/luprex/core/cpp/luastack.hpp index fc44d0de..f88bd34e 100644 --- a/luprex/core/cpp/luastack.hpp +++ b/luprex/core/cpp/luastack.hpp @@ -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; diff --git a/luprex/core/cpp/source.cpp b/luprex/core/cpp/source.cpp index 7ea4ff2b..a457ec59 100644 --- a/luprex/core/cpp/source.cpp +++ b/luprex/core/cpp/source.cpp @@ -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('_'); diff --git a/luprex/core/cpp/world-core.cpp b/luprex/core/cpp/world-core.cpp index 0ca46afa..ea3bc151 100644 --- a/luprex/core/cpp/world-core.cpp +++ b/luprex/core/cpp/world-core.cpp @@ -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; diff --git a/luprex/core/cpp/world-diffxmit.cpp b/luprex/core/cpp/world-diffxmit.cpp index e531ac55..98d192d5 100644 --- a/luprex/core/cpp/world-diffxmit.cpp +++ b/luprex/core/cpp/world-diffxmit.cpp @@ -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; } } diff --git a/luprex/core/lua/login.lua b/luprex/core/lua/login.lua index e39803de..c92924b4 100644 --- a/luprex/core/lua/login.lua +++ b/luprex/core/lua/login.lua @@ -1,15 +1,15 @@ -maketangible('login') +makeclass('login') function login.interface(actor, place) gui.menu_item("becomeplayer", "Become a Player") gui.menu_item("p123", "Print 1, 2, 3") end -function login.action.becomeplayer(actor, place, dialog) +function login.becomeplayer(actor, place, dialog) tangible.setclass(actor, player) end -function login.action.p123(actor, place, dialog) +function login.p123(actor, place, dialog) print(1) wait(1) print(2) diff --git a/luprex/core/lua/player.lua b/luprex/core/lua/player.lua index 7b1def2a..ebf5ce1f 100644 --- a/luprex/core/lua/player.lua +++ b/luprex/core/lua/player.lua @@ -1,4 +1,4 @@ -maketangible('player') +makeclass('player') function player.interface(actor, place) -- print("actor=", actor) @@ -16,25 +16,25 @@ function player:printanimstate() print("Resulting state: ", graphic, plane, x, y, z, facing) end -function player.action.north(actor, place, dialog) +function player.north(actor, place, dialog) print("Moving north") tangible.animate(place, {action="walk", dy=1}) actor:printanimstate() end -function player.action.south(actor, place, dialog) +function player.south(actor, place, dialog) print("Moving south") tangible.animate(place, {action="walk", dy=-1}) actor:printanimstate() end -function player.action.east(actor, place, dialog) +function player.east(actor, place, dialog) print("Moving east") tangible.animate(place, {action="walk", dx=1}) actor:printanimstate() end -function player.action.west(actor, place, dialog) +function player.west(actor, place, dialog) print("Moving west") tangible.animate(place, {action="walk", dx=-1}) actor:printanimstate()