13
0

LuaBindings: prefer shared_ptr over weak_ptr

This commit is contained in:
Robin Gareus 2017-01-21 20:06:54 +01:00
parent 4a5abf61b0
commit d0b42aee0e

View File

@ -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 <T>())
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 <T>& addFunction (char const* name, MemFn mf)
{
FUNDOC ("Weak/Shared Pointer Function", name, MemFn)
set_weak_class ();
CFunc::CallMemberWPtrFunctionHelper <MemFn>::add (L, name, mf);
set_shared_class ();
CFunc::CallMemberPtrFunctionHelper <MemFn>::add (L, name, mf);
set_weak_class ();
CFunc::CallMemberWPtrFunctionHelper <MemFn>::add (L, name, mf);
return *this;
}
@ -1248,11 +1248,11 @@ private:
WSPtrClass <T>& addRefFunction (char const* name, MemFn mf)
{
FUNDOC ("Weak/Shared Pointer Function RefReturn", name, MemFn)
set_weak_class ();
CFunc::CallMemberRefWPtrFunctionHelper <MemFn>::add (L, name, mf);
set_shared_class ();
CFunc::CallMemberRefPtrFunctionHelper <MemFn>::add (L, name, mf);
set_weak_class ();
CFunc::CallMemberRefWPtrFunctionHelper <MemFn>::add (L, name, mf);
return *this;
}
@ -1260,17 +1260,17 @@ private:
WSPtrClass <T>& addConstructor ()
{
FUNDOC ("Weak/Shared Pointer Constructor", "", MemFn)
set_shared_class ();
lua_pushcclosure (L,
&shared. template ctorPtrPlacementProxy <typename FuncTraits <MemFn>::Params, boost::shared_ptr<T>, 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 <typename FuncTraits <MemFn>::Params, boost::weak_ptr<T> >, 0);
rawsetfield(L, -2, "__call");
set_shared_class ();
lua_pushcclosure (L,
&shared. template ctorPtrPlacementProxy <typename FuncTraits <MemFn>::Params, boost::shared_ptr<T>, T >, 0);
rawsetfield(L, -2, "__call");
return *this;
}
@ -1282,12 +1282,12 @@ private:
WSPtrClass <T>& 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,32 +1313,32 @@ private:
WSPtrClass <T>& addNullCheck ()
{
PRINTDOC("Weak/Shared Null Check", _name << "isnil", std::string("bool"), std::string("void (*)()"))
set_weak_class ();
assert (lua_istable (L, -1));
lua_pushcclosure (L, &CFunc::WPtrNullCheck <T>::f, 0);
rawsetfield (L, -3, "isnil"); // class table
set_shared_class ();
assert (lua_istable (L, -1));
lua_pushcclosure (L, &CFunc::PtrNullCheck <T>::f, 0);
rawsetfield (L, -3, "isnil"); // class table
set_weak_class ();
assert (lua_istable (L, -1));
lua_pushcclosure (L, &CFunc::WPtrNullCheck <T>::f, 0);
rawsetfield (L, -3, "isnil"); // class table
return *this;
}
WSPtrClass <T>& addEqualCheck ()
{
PRINTDOC("Member Function", _name << "sameinstance", std::string("bool"), std::string("void (*)(" + type_name <T>() + ")"))
set_weak_class ();
assert (lua_istable (L, -1));
lua_pushcclosure (L, &CFunc::WPtrEqualCheck <T>::f, 0);
rawsetfield (L, -3, "sameinstance"); // class table
set_shared_class ();
assert (lua_istable (L, -1));
lua_pushcclosure (L, &CFunc::PtrEqualCheck <T>::f, 0);
rawsetfield (L, -3, "sameinstance"); // class table
set_weak_class ();
assert (lua_istable (L, -1));
lua_pushcclosure (L, &CFunc::WPtrEqualCheck <T>::f, 0);
rawsetfield (L, -3, "sameinstance"); // class table
return *this;
}
@ -1424,8 +1424,8 @@ private:
lua_insert (L, -3);
lua_insert (L, -2);
}
Class<boost::weak_ptr<T> > weak;
Class<boost::shared_ptr<T> > shared;
Class<boost::weak_ptr<T> > weak;
};