> On Wed, Jan 21, 2026 at 2:11 PM Eleanor Bartle <
essenc...@gmail.com> wrote:
> how is the __close metamethod of an object ordered with respect to the __gc metamethod?
_gc might be called only before _close, if you somehow "forgot" to
announce the object (which typcially will be userdata) to Lua ...
either by assigning the returned userdata reference to a Lua variable.
_close will then invoke, if this Lua variable gets killed.
Or if you use the userdata only internally in C, you must use
lua_setfield to add this userdata reference to the registry of your
lua state. I think _close might then be invoked when you kill this
reference by using lua_setfield for this registry reference again with
"nil value" to kill this reference.
... if you get _gc call before _close call, then somehow you did not
obeye such rules I would think... .