From 63bca62eddce6b17db9ab34fa2557e43a03e4ce3 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Tue, 23 Nov 2021 16:56:55 -0500 Subject: [PATCH] Fix tangible scans to return tangible lists --- luprex/core/cpp/world-accessor.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/luprex/core/cpp/world-accessor.cpp b/luprex/core/cpp/world-accessor.cpp index 54b87795..cab61250 100644 --- a/luprex/core/cpp/world-accessor.cpp +++ b/luprex/core/cpp/world-accessor.cpp @@ -2,6 +2,21 @@ #include "world.hpp" #include "pprint.hpp" +static void tangible_getall(LuaStack &LS0, LuaSlot list, const util::IdVector &idv) { + LuaVar tangibles, tan; + LuaStack LS(LS0.state(), tangibles, tan); + LS.rawget(tangibles, LuaRegistry, "tangibles"); + assert(LS.istable(tangibles)); + LS.set(list, LuaNewTable); + int index = 1; + for (int64_t id : idv) { + LS.rawget(tan, tangibles, id); + assert(LS.istable(tan)); + LS.rawset(list, index++, tan); + } + LS.result(); +} + LuaDefine(tangible_animstate, "c") { LuaArg tanobj; LuaRet graphic, plane, x, y, z, facing; @@ -208,9 +223,7 @@ LuaDefine(tangible_near, "c") { bool omit_self = LS.ckboolean(lomit_self); const AnimStep &aqback = tan->anim_queue_.back(); util::IdVector idv = w->plane_map_.scan_radius(aqback.plane(), aqback.xyz().x, aqback.xyz().y, radius, omit_nowhere, tan->id(), omit_self); - LS.set(list, LuaNewTable); - int index = 1; - for (int64_t id : idv) LS.rawset(list, index++, id); + tangible_getall(LS, list, idv); return LS.result(); } @@ -225,9 +238,7 @@ LuaDefine(tangible_scan, "c") { double radius = LS.cknumber(lradius); bool omit_nowhere = LS.ckboolean(lomit_nowhere); util::IdVector idv = w->plane_map_.scan_radius(plane, x, y, radius, omit_nowhere, 0, false); - LS.set(list, LuaNewTable); - int index = 1; - for (int64_t id : idv) LS.rawset(list, index++, id); + tangible_getall(LS, list, idv); return LS.result(); }