forked from luabind/luabind
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve shared_ptr support (closes #4).
The following only applies if one of the shared_ptr_converter or std_shared_ptr_converter headers is included. shared_ptr means std:: or boost::shared_ptr if the latter is included but only boost::shared_ptr if just shared_ptr_converter is included (yes, that's a bit counter inuitive): 1. If the shared_ptr requested (from C++) has the exact same type as the one which is present in Lua (if any), the behavior is now the same as with the automatic smart pointer support (i.e. use_count will be increased properly but raw object equality in Lua won't be preserved). 2. If the pointee type of the requested shared_ptr has a shared_from_this member function (checked automatically at compile time), this will be used to obtain a shared_ptr. Caveats: (1) If the object is not already hold in a shared_ptr, behavior is undefined (probably a bad_weak_ptr exception will be thrown). (2) If the enable_shared_from_this() member is not a function with the right prototype (ptr_t enable_shared_from_this() with ptr_t being convertible to the requested shared_ptr<T> type) a compile time error will result. 3. Otherwise, behavior is the same as for boost::shared_ptr before this change: A new shared_ptr will be created from the raw pointer associated with the Lua object (even if it is not held in a shared_ptr) whose deleter holds a strong reference to the Lua object, thus preventing it's destruction until the reference is released by invoking the deleter (i.e. by resetting or destroying the shared_ptr) or (and this could be problematic) until the asocciated lua_State is closed. The ideal solution would of course be to return the equivalent of static_cast<requested_shared_ptr>(original_shared_ptr), but this would only be possible for a fixed set of smart pointer types, requiring luabind to generate cast functions between the shared_ptrs -- a major overhaul to the already very complicated inheritance/cast system which currently relies on caching ptrdiff_ts and passing void* around which are (contrary to shared_ptr) trivially destructible.
- Loading branch information
Showing
4 changed files
with
216 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.