[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [LUA]: Cannot use userdata as table index
- From: Choonster TheMage <choonster.2010@...>
- Date: Sat, 11 Jul 2015 02:08:11 +1000
On 11 July 2015 at 01:59, Борис Александров <boriscool007@gmail.com> wrote:
> Player(0)Player(0)
>
> 2015-07-11 1:44 GMT+10:00 Rob Kendrick <rjek@rjek.com>:
>>
>> On Sat, Jul 11, 2015 at 01:41:44AM +1000, Борис Александров wrote:
>> > Example code:
>> >
>> > " temp = {}
>> > temp['string'] = 'foobar'
>> > temp[GetPlayer(0)] = 'player'
>> > temp[GetEntity(0)] = 'entity'
>> >
>> > print(temp['string']) -- foobar
>> > print(temp[GetPlayer(0)]) -- nil
>> > print(temp[GetEntity(0)]) -- nil
>>
>>
>> What does the following display?
>> print(GetPlayer(0), GetPlayer(0))
>>
>> B.
>>
>
Can you remove the __eq and __tostring metamethods from the userdata
and run this code?
print("Equal?", GetPlayer(0) == GetPlayer(0))
print("Addresses", GetPlayer(0), GetPlayer(0))
If GetPlayer always returns the same userdata for a given player ID,
the first line should be "Equal? true" and the second should have the
same hexadecimal digit twice.
If GetPlayer returns a different userdata each time, you won't be able
to use it as a table key reliably (since the userdata objects won't be
raw equal to each other).
Regards,
Choonster