Re: Object identity
eduard mueller <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
On Tue, May 24, 2011 at 17:59, Josh Klint <[email protected]> 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 [email protected] https://lists.sourceforge.net/lists/listinfo/luabind-user