From d0b42aee0ed4e028d8fc4f8dba8dc0c3670cdbbe Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 21 Jan 2017 20:06:54 +0100 Subject: LuaBindings: prefer shared_ptr over weak_ptr --- libs/lua/LuaBridge/detail/Namespace.h | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'libs/lua') diff --git a/libs/lua/LuaBridge/detail/Namespace.h b/libs/lua/LuaBridge/detail/Namespace.h index 98383a4f6c..7f8d44859c 100644 --- a/libs/lua/LuaBridge/detail/Namespace.h +++ b/libs/lua/LuaBridge/detail/Namespace.h @@ -1203,8 +1203,8 @@ private: public: WSPtrClass (char const* name, Namespace const* parent) : ClassBase (parent->L) - , weak (name, parent) , shared (name, parent) + , weak (name, parent) { #ifdef LUABINDINGDOC _parent = parent; @@ -1213,21 +1213,21 @@ private: PRINTDOC ("[C] Weak/Shared Pointer Class", parent->_name + name, std::string(), type_name ()) - m_stackSize = weak.m_stackSize; + m_stackSize = shared.m_stackSize; parent->m_stackSize = weak.m_stackSize = shared.m_stackSize = 0; lua_pop (L, 3); } WSPtrClass (char const* name, Namespace const* parent, void const* const sharedkey, void const* const weakkey) : ClassBase (parent->L) - , weak (name, parent, weakkey) , shared (name, parent, sharedkey) + , weak (name, parent, weakkey) { #ifdef LUABINDINGDOC _parent = parent; _name = parent->_name + name + ":"; #endif - m_stackSize = weak.m_stackSize; + m_stackSize = shared.m_stackSize; parent->m_stackSize = weak.m_stackSize = shared.m_stackSize = 0; lua_pop (L, 3); } @@ -1236,11 +1236,11 @@ private: WSPtrClass & addFunction (char const* name, MemFn mf) { FUNDOC ("Weak/Shared Pointer Function", name, MemFn) - set_weak_class (); - CFunc::CallMemberWPtrFunctionHelper ::add (L, name, mf); - set_shared_class (); CFunc::CallMemberPtrFunctionHelper ::add (L, name, mf); + + set_weak_class (); + CFunc::CallMemberWPtrFunctionHelper ::add (L, name, mf); return *this; } @@ -1248,11 +1248,11 @@ private: WSPtrClass & addRefFunction (char const* name, MemFn mf) { FUNDOC ("Weak/Shared Pointer Function RefReturn", name, MemFn) - set_weak_class (); - CFunc::CallMemberRefWPtrFunctionHelper ::add (L, name, mf); - set_shared_class (); CFunc::CallMemberRefPtrFunctionHelper ::add (L, name, mf); + + set_weak_class (); + CFunc::CallMemberRefWPtrFunctionHelper ::add (L, name, mf); return *this; } @@ -1260,17 +1260,17 @@ private: WSPtrClass & addConstructor () { FUNDOC ("Weak/Shared Pointer Constructor", "", MemFn) + set_shared_class (); + lua_pushcclosure (L, + &shared. template ctorPtrPlacementProxy ::Params, 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 ctorPlacementProxy ::Params, boost::weak_ptr >, 0); rawsetfield(L, -2, "__call"); - - set_shared_class (); - lua_pushcclosure (L, - &shared. template ctorPtrPlacementProxy ::Params, boost::shared_ptr, T >, 0); - rawsetfield(L, -2, "__call"); return *this; } @@ -1282,12 +1282,12 @@ private: WSPtrClass & addExtCFunction (char const* name, int (*const fp)(lua_State*)) { DATADOC ("Weak/Shared Ext C Function", name, fp) - set_weak_class (); + set_shared_class (); assert (lua_istable (L, -1)); lua_pushcclosure (L, fp, 0); rawsetfield (L, -3, name); // class table - set_shared_class (); + set_weak_class (); assert (lua_istable (L, -1)); lua_pushcclosure (L, fp, 0); rawsetfield (L, -3, name); // class table @@ -1313,14 +1313,14 @@ private: WSPtrClass & addNullCheck () { PRINTDOC("Weak/Shared Null Check", _name << "isnil", std::string("bool"), std::string("void (*)()")) - set_weak_class (); + set_shared_class (); assert (lua_istable (L, -1)); - lua_pushcclosure (L, &CFunc::WPtrNullCheck ::f, 0); + lua_pushcclosure (L, &CFunc::PtrNullCheck ::f, 0); rawsetfield (L, -3, "isnil"); // class table - set_shared_class (); + set_weak_class (); assert (lua_istable (L, -1)); - lua_pushcclosure (L, &CFunc::PtrNullCheck ::f, 0); + lua_pushcclosure (L, &CFunc::WPtrNullCheck ::f, 0); rawsetfield (L, -3, "isnil"); // class table return *this; @@ -1329,14 +1329,14 @@ private: WSPtrClass & addEqualCheck () { PRINTDOC("Member Function", _name << "sameinstance", std::string("bool"), std::string("void (*)(" + type_name () + ")")) - set_weak_class (); + set_shared_class (); assert (lua_istable (L, -1)); - lua_pushcclosure (L, &CFunc::WPtrEqualCheck ::f, 0); + lua_pushcclosure (L, &CFunc::PtrEqualCheck ::f, 0); rawsetfield (L, -3, "sameinstance"); // class table - set_shared_class (); + set_weak_class (); assert (lua_istable (L, -1)); - lua_pushcclosure (L, &CFunc::PtrEqualCheck ::f, 0); + lua_pushcclosure (L, &CFunc::WPtrEqualCheck ::f, 0); rawsetfield (L, -3, "sameinstance"); // class table return *this; @@ -1424,8 +1424,8 @@ private: lua_insert (L, -3); lua_insert (L, -2); } - Class > weak; Class > shared; + Class > weak; }; -- cgit v1.2.3