aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-02-12 14:59:06 +0100
committersfan5 <sfan5@live.de>2020-02-23 22:24:12 +0100
commit4da057cc49082192bbc45689d80dec3410e41f27 (patch)
tree7c20ad276c382db88794eaff13ba2bb3d7857722 /src/script/cpp_api
parent2df226bb41904bfd80c33f243996ee7b1bd7e907 (diff)
downloadminetest-4da057cc49082192bbc45689d80dec3410e41f27.tar.gz
minetest-4da057cc49082192bbc45689d80dec3410e41f27.tar.bz2
minetest-4da057cc49082192bbc45689d80dec3410e41f27.zip
Script API: Document ObjectRef handling in a comment
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r--src/script/cpp_api/s_base.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp
index 1f40bb06a..ecb1ba39b 100644
--- a/src/script/cpp_api/s_base.cpp
+++ b/src/script/cpp_api/s_base.cpp
@@ -333,6 +333,20 @@ void ScriptApiBase::setOriginFromTableRaw(int index, const char *fxn)
#endif
}
+/*
+ * How ObjectRefs are handled in Lua:
+ * When an active object is created, an ObjectRef is created on the Lua side
+ * and stored in core.object_refs[id].
+ * Methods that require an ObjectRef to a certain object retrieve it from that
+ * table instead of creating their own.(*)
+ * When an active object is removed, the existing ObjectRef is invalidated
+ * using ::set_null() and removed from the core.object_refs table.
+ * (*) An exception to this are NULL ObjectRefs and anonymous ObjectRefs
+ * for objects without ID.
+ * It's unclear what the latter are needed for and their use is problematic
+ * since we lose control over the ref and the contained pointer.
+ */
+
void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
{
SCRIPTAPI_PRECHECKHEADER