I have a void *
to a C++ created object that I pass to Lua using lua_pushlightuserdata()
. Lua can perform some actions on that light userdata by passing it to Lua CFunctions and retrieving it with lua_touserdata()
. At some point in the future the C++ object is destructed by its owner (C++), memory freed, and set to null. However, Lua still has a reference to this pointer, it doesn't know that it has been destroyed.
Now my Lua functions that take in this userdata make sure the pointer is valid. But what is the best approach for informing Lua that their reference to the light userdata is no longer valid? Do I expose an IsValid(lightuserdata)
function to Lua so it can query the status? Or is there a better approach that I am missing.