From 1d512ef7f4071fadf10078825ce83e77a3707f06 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 3 Jul 2022 16:44:08 +0200 Subject: Reduce code duplication between c_converter.cpp and helper.cpp --- src/script/common/c_converter.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/script/common/c_converter.cpp') diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 109fa1a14..69da35b73 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -61,6 +61,22 @@ static void set_vector_metatable(lua_State *L) lua_setmetatable(L, -2); } +// Retrieve an integer vector where all components are optional +template +static bool getv3intfield(lua_State *L, int index, + const char *fieldname, T &result) +{ + lua_getfield(L, index, fieldname); + bool got = false; + if (lua_istable(L, -1)) { + got |= getintfield(L, -1, "x", result.X); + got |= getintfield(L, -1, "y", result.Y); + got |= getintfield(L, -1, "z", result.Z); + } + lua_pop(L, 1); + return got; +} + void push_v3f(lua_State *L, v3f p) { lua_createtable(L, 0, 3); -- cgit v1.2.3