aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorZughy <63455151+Zughy@users.noreply.github.com>2020-10-13 21:27:52 +0200
committerGitHub <noreply@github.com>2020-10-13 20:27:52 +0100
commit2341a4aff1242e978d6fad3772d4d4fb015c040d (patch)
treedeace790c7c9739bda1b4578991e3dbb9ecffab3 /src/script
parent521a04222a71325ef217d1214febf5591919e169 (diff)
downloadminetest-2341a4aff1242e978d6fad3772d4d4fb015c040d.tar.gz
minetest-2341a4aff1242e978d6fad3772d4d4fb015c040d.tar.bz2
minetest-2341a4aff1242e978d6fad3772d4d4fb015c040d.zip
Add ObjectRef:get_children() (#10480)
Co-authored-by: Zughy <4279489-marco_a@users.noreply.gitlab.com>
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_object.cpp22
-rw-r--r--src/script/lua_api/l_object.h3
2 files changed, 25 insertions, 0 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 57ed7e2cd..96c8c687c 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -738,6 +738,27 @@ int ObjectRef::l_get_attach(lua_State *L)
return 5;
}
+// get_children(self)
+int ObjectRef::l_get_children(lua_State *L)
+{
+ GET_ENV_PTR;
+
+ ObjectRef *ref = checkobject(L, 1);
+ ServerActiveObject *sao = getobject(ref);
+ if (sao == nullptr)
+ return 0;
+
+ const std::unordered_set<int> child_ids = sao->getAttachmentChildIds();
+ int i = 0;
+ lua_createtable(L, child_ids.size(), 0);
+ for (const int id : child_ids) {
+ ServerActiveObject *child = env->getActiveObject(id);
+ getScriptApiBase(L)->objectrefGetOrCreate(L, child);
+ lua_rawseti(L, -2, ++i);
+ }
+ return 1;
+}
+
// set_detach(self)
int ObjectRef::l_set_detach(lua_State *L)
{
@@ -2337,6 +2358,7 @@ luaL_Reg ObjectRef::methods[] = {
luamethod(ObjectRef, get_bone_position),
luamethod(ObjectRef, set_attach),
luamethod(ObjectRef, get_attach),
+ luamethod(ObjectRef, get_children),
luamethod(ObjectRef, set_detach),
luamethod(ObjectRef, set_properties),
luamethod(ObjectRef, get_properties),
diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h
index ca03dfa2e..097a74cae 100644
--- a/src/script/lua_api/l_object.h
+++ b/src/script/lua_api/l_object.h
@@ -143,6 +143,9 @@ private:
// get_attach(self)
static int l_get_attach(lua_State *L);
+ // get_children(self)
+ static int l_get_children(lua_State *L);
+
// set_detach(self)
static int l_set_detach(lua_State *L);