Skip to content

Commit 4da057c

Browse files
committedFeb 23, 2020
Script API: Document ObjectRef handling in a comment
1 parent 2df226b commit 4da057c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

Diff for: ‎src/script/cpp_api/s_base.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,20 @@ void ScriptApiBase::setOriginFromTableRaw(int index, const char *fxn)
333333
#endif
334334
}
335335

336+
/*
337+
* How ObjectRefs are handled in Lua:
338+
* When an active object is created, an ObjectRef is created on the Lua side
339+
* and stored in core.object_refs[id].
340+
* Methods that require an ObjectRef to a certain object retrieve it from that
341+
* table instead of creating their own.(*)
342+
* When an active object is removed, the existing ObjectRef is invalidated
343+
* using ::set_null() and removed from the core.object_refs table.
344+
* (*) An exception to this are NULL ObjectRefs and anonymous ObjectRefs
345+
* for objects without ID.
346+
* It's unclear what the latter are needed for and their use is problematic
347+
* since we lose control over the ref and the contained pointer.
348+
*/
349+
336350
void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
337351
{
338352
SCRIPTAPI_PRECHECKHEADER

0 commit comments

Comments
 (0)
Please sign in to comment.