redux and fix? objects derived from wrap_base

"Thomas Nelson" <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <9F61B9459784487EAC251F9C4AB4C5AA@Spawn>
I was running into a problem a while ago with objects derived from
luabind:wrap_base.  I think I have a fix but would like some feedback on
whether or not I'm completely off base and what some of the side effects may
be.

The problem:
I have a class structure that looks like this:

class MyObject: public luabind::wrap_base
{
    public:
        MyObject(): luabind::wrap_base {}
};


MyObject *pObj = new MyObject();
luabind::globals(pLState)["_Object"] = pObj;

In the code, this assignment will assert, wrap_base is constructed with its
default constructor and when push attempts to determine the back reference
it chokes since there is no lua state associated with the object.

The fix?:
In weakref.cpp change the state method to look like this:
lua_State* weak_ref::state() const
{ // removed the assert and added an explicit NULL return
--> if (m_impl)
-->     return m_impl->state;
--> return NULL;
}

In back_reference.hpp add the two marked lines to get_back_reference:
template<class T>
bool get_back_reference(lua_State* L, T const& x)
{
#ifndef LUABIND_NO_RTTI
    if (wrap_base const* w = detail::get_back_reference(x))
    { 
-->     if (!detail::wrap_access::ref(*w).state())
-->         return false;
        detail::wrap_access::ref(*w).get(L);
        return true;
    }
#endif
    return false;
}

--
Thomas Nelson  [email protected]  
--------------------------------------------------------------
"If you still have gas, you're not lost".
- French explorer Pierre Frontage.
(M.Frontage was so influential in the exploration of North America many
roads are still named after him.)




------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.