From 6f7f527e1db300fb532390348db132446a211085 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 21 Jan 2017 20:07:54 +0100 Subject: Lua add an Empty/Nil shared-pointer constructor --- libs/lua/LuaBridge/detail/Namespace.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'libs/lua') 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 + static int ctorNilPtrPlacementProxy (lua_State* L) + { + const T* newobject = new T (); + Stack::push (L, *newobject); + return 1; + } + //-------------------------------------------------------------------------- /** Pop the Lua stack. @@ -1279,6 +1287,24 @@ private: return addConstructor (); } + WSPtrClass & addNilPtrConstructor () + { + FUNDOC ("Weak/Shared Pointer Constructor", "", MemFn) + set_shared_class (); + lua_pushcclosure (L, + &shared. template ctorNilPtrPlacementProxy >, 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 >, 0); + rawsetfield(L, -2, "__call"); + + return *this; + } + WSPtrClass & addExtCFunction (char const* name, int (*const fp)(lua_State*)) { DATADOC ("Weak/Shared Ext C Function", name, fp) -- cgit v1.2.3