lua-users home
lua-l archive

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


You and Jerome have hit the nail on the head.  They are userdata created
with different lua_newuserdata calls.  I hadn't considered the
posibility that they would get seperate hash values if they contain the
same data, this seems a little odd being as two seperate strings get
hashed to the same value if they have the same value, but I'll let it
slide :)

> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br 
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of 
> Matt Campbell
> Sent: 25 January 2008 16:28
> To: Lua list
> Subject: Re: Hashing userdata
> 
> OK, are both "key" and "v.key" references to the same Lua userdata? 
> That is, do they both come from the same invocation of 
> lua_newuserdata?
> 
> I'm guessing the answer is no.  What you need is a table, 
> probably only referenced in the Lua registry, which maps C++ 
> pointers (as Lua light
> userdata) to the corresponding full userdata.  This table 
> should have weak values; that is, its metatable's "__mode" 
> field should be set to "v".  Then, whenever your C++ code 
> needs to send an object to Lua, it should first look up the 
> object's pointer (again, as light userdata) in this cache 
> table.  If a corresponding full userdata object is found, the 
> C++ code should send that to Lua.  Otherwise, it should create a new
> full userdata object and map that to the C++ pointer in the 
> cache table before sending it to Lua.  Then there will be 
> only one Lua userdata object for each C++ object.
> 
> Matt
> 


 
---------------------------------------------------------------------------- 
         DISCLAIMER 
This email is sent by The Creative Assembly Limited company No. 03425917, registered in England &Wales registered office 27 Great West Road, Middlesex, TW8 9BW, England. The contents of this e-mail and any attachments are confidential to the intended recipient and may also be legally privileged. Unless you are the named addressee (or authorised to receive for the addressee) of this email you may not copy, disclose or distribute it to anyone else. If you have received this email in error, please notify us immediately by e-mail on postmaster@creative-assembly.co.uk and then delete the email and any copies. The Creative Assembly Limited have made all reasonable efforts to ensure that this e-mail and any attached documents or software are free from software viruses, but it is the recipient's responsibility to confirm this.