add "sameinstance()" lua binding for all shared/weak ptrs
This commit is contained in:
parent
ddc4e61b57
commit
1d7c144967
@ -401,7 +401,6 @@ struct CFunc
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct PtrNullCheck
|
struct PtrNullCheck
|
||||||
{
|
{
|
||||||
@ -430,6 +429,38 @@ struct CFunc
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct PtrEqualCheck
|
||||||
|
{
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
boost::shared_ptr<T> t0 = luabridge::Stack<boost::shared_ptr<T> >::get (L, 1);
|
||||||
|
boost::shared_ptr<T> t1 = luabridge::Stack<boost::shared_ptr<T> >::get (L, 2);
|
||||||
|
Stack <bool>::push (L, t0 == t1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct WPtrEqualCheck
|
||||||
|
{
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
bool rv = false;
|
||||||
|
boost::weak_ptr<T> tw0 = luabridge::Stack<boost::weak_ptr<T> >::get (L, 1);
|
||||||
|
boost::weak_ptr<T> tw1 = luabridge::Stack<boost::weak_ptr<T> >::get (L, 2);
|
||||||
|
boost::shared_ptr<T> const t0 = tw0.lock();
|
||||||
|
boost::shared_ptr<T> const t1 = tw1.lock();
|
||||||
|
if (t0 && t1) {
|
||||||
|
T* const tt0 = t0.get();
|
||||||
|
T* const tt1 = t1.get();
|
||||||
|
rv = (tt0 == tt1);
|
||||||
|
}
|
||||||
|
Stack <bool>::push (L, rv);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <class MemFnPtr, class T,
|
template <class MemFnPtr, class T,
|
||||||
class ReturnType = typename FuncTraits <MemFnPtr>::ReturnType>
|
class ReturnType = typename FuncTraits <MemFnPtr>::ReturnType>
|
||||||
struct CallMemberWPtr
|
struct CallMemberWPtr
|
||||||
|
@ -1298,6 +1298,21 @@ private:
|
|||||||
return *this;
|
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, "isnil"); // class table
|
||||||
|
|
||||||
|
set_shared_class ();
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_pushcclosure (L, &CFunc::PtrEqualCheck <T>::f, 0);
|
||||||
|
rawsetfield (L, -3, "isnil"); // class table
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Namespace endClass ()
|
Namespace endClass ()
|
||||||
{
|
{
|
||||||
@ -1652,7 +1667,8 @@ public:
|
|||||||
WSPtrClass <T> beginWSPtrClass (char const* name)
|
WSPtrClass <T> beginWSPtrClass (char const* name)
|
||||||
{
|
{
|
||||||
return WSPtrClass <T> (name, this)
|
return WSPtrClass <T> (name, this)
|
||||||
.addNullCheck();
|
.addNullCheck()
|
||||||
|
.addEqualCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user