The "weaktable" keeps a weak reference to the existing Lua USERDATA, so
when I "push" an object from C++ and there is an existing Lua object, it
can push a reference to it rather than creating a new Lua USERDATA (I
find that, in games especially, you end up with a LOT of extra garbage
collection if you have to create a new USERDATA every time you want C++
to push the object). While the main object USERDATA exists, maintable[2]
holds a strong C++ reference (shared_ptr) to the object, so it won't be
deleted on the C++ side. When the USERDATA ends up being garbage
collected, the shared_ptr<> is deleted, releasing the C++ reference.