lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Tom Miles wrote:
> I have some code in C++ that takes a pointer and sends it to lua as a
> full userdata.  Both key and v.key are userdata sent to lua in this
> way.  

My guess is that your two variables (key and v.key) point to two
identical but distinct userdata (that is created by two distinct calls
to lua_newuserdata). When used as key in a table, the content of the
full userdata is simply ignored by the hash function, only the address
of the userdata itself (which is allocated by Lua, not the address of
your C object) is taken into account.

You have two solutions to this. The first one is to make sure that both
your variables point to the same userdata, which may be hard to achieve
depending on the complexity of the code. The other solution is to use
light userdata. Light userdata containing the same address will resolve
to the same hash, even if created separately via two calls to
lua_pushlightuserdata.