summaryrefslogtreecommitdiff
path: root/src/script/common/c_converter.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-07-03 16:44:08 +0200
committersfan5 <sfan5@live.de>2022-07-14 20:55:45 +0200
commit1d512ef7f4071fadf10078825ce83e77a3707f06 (patch)
treea839a9a84868b28b633b98b85bc158f0cb6ac4c9 /src/script/common/c_converter.cpp
parent8ff3fadba033dbc686c4f834811f0744099fedfb (diff)
downloadminetest-1d512ef7f4071fadf10078825ce83e77a3707f06.tar.gz
minetest-1d512ef7f4071fadf10078825ce83e77a3707f06.tar.bz2
minetest-1d512ef7f4071fadf10078825ce83e77a3707f06.zip
Reduce code duplication between c_converter.cpp and helper.cpp
Diffstat (limited to 'src/script/common/c_converter.cpp')
-rw-r--r--src/script/common/c_converter.cpp16
1 files changed, 16 insertions, 0 deletions
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<class T>
+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);