diff --git a/luprex/cpp/core/world-core.cpp b/luprex/cpp/core/world-core.cpp index 93e4d2d2..308820b7 100644 --- a/luprex/cpp/core/world-core.cpp +++ b/luprex/cpp/core/world-core.cpp @@ -769,6 +769,41 @@ void World::invoke_choose(int64_t actor_id, int64_t place_id, std::string_view d assert(stack_is_clear()); } +// Read a SimpleDynamic value from the streambuffer and push +// it onto the lua stack. +void push_simple_dynamic(lua_State *L, StreamBuffer *sb) { + SimpleDynamicTag type = sb->read_simple_dynamic_tag(); + switch (type) { + case SimpleDynamicTag::NUMBER: { + lua_pushnumber(L, sb->read_double()); + break; + } + case SimpleDynamicTag::BOOLEAN: { + lua_pushboolean(L, sb->read_bool() ? 1:0); + break; + } + case SimpleDynamicTag::STRING: { + std::string_view s = sb->read_string_view(); + lua_pushlstring(L, s.data(), s.size()); + break; + } + case SimpleDynamicTag::VECTOR: { + double x = sb->read_double(); + double y = sb->read_double(); + double z = sb->read_double(); + lua_newtable(L); + lua_pushnumber(L, x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, y); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, z); + lua_rawseti(L, -2, 3); + break; + } + default: throw StreamCorruption(); + } +} + void World::invoke_engio(int64_t actor_id, int64_t place_id, std::string_view datapack) { assert(stack_is_clear()); @@ -820,7 +855,7 @@ void World::invoke_engio(int64_t actor_id, int64_t place_id, std::string_view da if (!LS.isfunction(func)) { return; } - + // Create a new thread, push func, actor, place. int nargs = 3; lua_State *CO = LS.newthread(thread); @@ -831,23 +866,7 @@ void World::invoke_engio(int64_t actor_id, int64_t place_id, std::string_view da // Push any additional args from the datapack. try { while (!datasb.empty()) { - SimpleDynamicTag type = datasb.read_simple_dynamic_tag(); - switch (type) { - case SimpleDynamicTag::NUMBER: { - lua_pushnumber(L, datasb.read_double()); - break; - } - case SimpleDynamicTag::BOOLEAN: { - lua_pushboolean(L, datasb.read_bool() ? 1:0); - break; - } - case SimpleDynamicTag::STRING: { - std::string_view s = datasb.read_string_view(); - lua_pushlstring(L, s.data(), s.size()); - break; - } - default: return; - } + push_simple_dynamic(L, &datasb); nargs++; } } catch (const StreamException &exc) { diff --git a/luprex/lua/login.lua b/luprex/lua/login.lua index 08197eae..5e5631c9 100644 --- a/luprex/lua/login.lua +++ b/luprex/lua/login.lua @@ -53,5 +53,8 @@ function mkt() makeclass("engio") function engio.myfunction(actor, place, a, b, c) - print("Myfunction actor=", actor," place=", place, " a=", a, " b=", b, " c=", c) + print("Myfunction actor=", actor," place=", place) + pprint("A:", a) + pprint("B:", b) + pprint("C:", c) end