From 028bbca07b813837b34db3799a20b206c8b0291e Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 2 Mar 2023 19:32:10 -0800 Subject: [PATCH] allow vectors to be read from indices other than 1 --- library/LuaTools.cpp | 4 ++-- library/include/LuaTools.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/LuaTools.cpp b/library/LuaTools.cpp index ed0b0699d..a1bf855d6 100644 --- a/library/LuaTools.cpp +++ b/library/LuaTools.cpp @@ -121,10 +121,10 @@ void DFHack::Lua::Push(lua_State *state, const df::coord2d &pos) lua_setfield(state, -2, "y"); } -void DFHack::Lua::GetVector(lua_State *state, std::vector &pvec) +void DFHack::Lua::GetVector(lua_State *state, std::vector &pvec, int idx) { lua_pushnil(state); // first key - while (lua_next(state, 1) != 0) + while (lua_next(state, idx) != 0) { pvec.push_back(lua_tostring(state, -1)); lua_pop(state, 1); // remove value, leave key diff --git a/library/include/LuaTools.h b/library/include/LuaTools.h index 86d3d0c7e..689d82260 100644 --- a/library/include/LuaTools.h +++ b/library/include/LuaTools.h @@ -359,7 +359,7 @@ namespace DFHack {namespace Lua { } } - DFHACK_EXPORT void GetVector(lua_State *state, std::vector &pvec); + DFHACK_EXPORT void GetVector(lua_State *state, std::vector &pvec, int idx = 1); DFHACK_EXPORT int PushPosXYZ(lua_State *state, const df::coord &pos); DFHACK_EXPORT int PushPosXY(lua_State *state, const df::coord2d &pos);