I often use the C++11 class std::shared_ptr<> template class to push
to Lua objects and it's great because it handles reference counting,
that is if the host does not own the ressource, Lua will delete it
later with the __gc. But the drawback, is that you usually push a new
shared_ptr<> instance with the same underlying object, thus the
pointer of the userdata is different but not its content.
You'll end up with a huge table of the same data because the pointer
of myuserdata is different (but not its content!). I usually
workaround with mytable[myuserdata:getId()] or something similar.