Object identity

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Object identity

Josh Klint

Can no one answer this?  Luabind is the only binding library that does not appear to be abandoned.  If I can’t solve this, I am going to drop Lua.

I have my classes and binding set up as follows:

class Object

class Object_wrap : public Object, public luabind::wrap_base {};

 

class Entity : public Object

class Entity_wrap : public Entity, public luabind::wrap_base {};

 

class Model : public Entity

class Model_wrap : public Entity, public luabind::wrap_base {};

 

class_<Object,Object_wrap>("Object")

class_<Entity,Entity_wrap,Object>("Entity")

class_<Model,Model_wrap,Entity,Object>("Model")

 

Is that all I have to do to make luabind consistently use the same luabind::object?  It doesn’t appear to have any effect.

 

 

Best Regards,

 

Josh Klint

CEO

Leadwerks Software

www.leadwerks.com

 


------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Object identity

eduard mueller
On Tue, May 24, 2011 at 17:59, Josh Klint <[hidden email]> wrote:
> Is that all I have to do to make luabind consistently use the same
> luabind::object?  It doesn’t appear to have any effect.

May help if you explain what exactly you mean with "same". What
exactly you are trying to accomplish where and how?

If you want to compare LuaBind class objects in Lua. You can do something like:

int RawEqual(lua_State* L)
{
  // need two valid args
  ::luaL_checkany(L, 1);
  ::luaL_checkany(L, 2);

  // check if the objects on the stack are luabind objects
  if (::lua_type(L, 1) == LUA_TUSERDATA && ::lua_type(L, 2) == LUA_TUSERDATA)
  {
    luabind::detail::object_rep* pObj1 = luabind::detail::get_instance(L, 1);
    luabind::detail::object_rep* pObj2 = luabind::detail::get_instance(L, 2);

    if (pObj1 != NULL && pObj2 != NULL)
    {
      const std::pair<void*, int> Instance1 =
        pObj1->get_instance(pObj1->crep()->classes().get(pObj1->crep()->type()));

      const std::pair<void*, int> Instance2 =
        pObj2->get_instance(pObj2->crep()->classes().get(pObj2->crep()->type()));

      if (Instance1.first != NULL && Instance2.first != NULL)
      {
        // return object identity only (naked ptrs)
        // get_instance() unwraps smart ptrs already
        ::lua_pushboolean(L, (Instance1.first == Instance2.first));
        return 1;
      }
    }
  }

  ::lua_pushboolean(L, ::lua_rawequal(L, 1, 2));
  return 1;
}


the "get_instance" is a bit of a hack. Not sure if there's an easier way.

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Object identity

liam mail
In reply to this post by Josh Klint


On 24 May 2011 16:59, Josh Klint <[hidden email]> wrote:

Luabind is the only binding library that does not appear to be abandoned. 

That is not true Josh although I am not about to discuss other bindings on this mailing list. I have seen your many postings here and on gamedev and can understand your frustration, why not try the Lua mailing list or IRC channel for alternatives, most of which I should note are listed on the Lua wiki.
 

If I can’t solve this, I am going to drop Lua.


Can I suggest you pick up the Teddy which you threw in the corner there :)

Liam

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user