Interesting...
One could combine this with the weak table approach by setting a weak
table
as the __index table for the registry. That way, when you wanted to
keep the
object alive for reasons outside of Lua, you would put it in the main
registry. If that reference went away, however, you could still get to
it
via the weak table backing up the registry.
Theoretically, you shouldn't need the weak table, but this would allow
member functions to push "this" to the stack without worrying about
whether
they could use a pre-existing stack entry for the userdata. I'm
thinking
about whether that's actually an issue in practice.