diff options
author | Robin Gareus <robin@gareus.org> | 2017-01-21 20:07:54 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2017-01-21 20:18:27 +0100 |
commit | 6f7f527e1db300fb532390348db132446a211085 (patch) | |
tree | bc1aaf5ada43696e5e3919dedce9a85f4be73499 /libs/lua/LuaBridge | |
parent | d0b42aee0ed4e028d8fc4f8dba8dc0c3670cdbbe (diff) |
Lua add an Empty/Nil shared-pointer constructor
Diffstat (limited to 'libs/lua/LuaBridge')
-rw-r--r-- | libs/lua/LuaBridge/detail/Namespace.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libs/lua/LuaBridge/detail/Namespace.h b/libs/lua/LuaBridge/detail/Namespace.h index 7f8d44859c..9a9b3c44cb 100644 --- a/libs/lua/LuaBridge/detail/Namespace.h +++ b/libs/lua/LuaBridge/detail/Namespace.h @@ -482,6 +482,14 @@ private: return 1; } + template <class T> + static int ctorNilPtrPlacementProxy (lua_State* L) + { + const T* newobject = new T (); + Stack<T>::push (L, *newobject); + return 1; + } + //-------------------------------------------------------------------------- /** Pop the Lua stack. @@ -1279,6 +1287,24 @@ private: return addConstructor <void (*) ()> (); } + WSPtrClass <T>& addNilPtrConstructor () + { + FUNDOC ("Weak/Shared Pointer Constructor", "", MemFn) + set_shared_class (); + lua_pushcclosure (L, + &shared. template ctorNilPtrPlacementProxy <boost::shared_ptr<T> >, 0); + rawsetfield(L, -2, "__call"); + + set_weak_class (); + // NOTE: this constructs an empty weak-ptr, + // ideally we'd construct a weak-ptr from a referenced shared-ptr + lua_pushcclosure (L, + &weak. template ctorNilPtrPlacementProxy <boost::weak_ptr<T> >, 0); + rawsetfield(L, -2, "__call"); + + return *this; + } + WSPtrClass <T>& addExtCFunction (char const* name, int (*const fp)(lua_State*)) { DATADOC ("Weak/Shared Ext C Function", name, fp) |