[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: AW: userdata as table-key
- From: "Michaela Kyavar" <michaela.kyavar@...>
- Date: Sun, 25 Apr 2004 20:35:07 +0200
Hi Ashwin! Thankyou for the answer.
No, I changed the variables somewhat (shortened) for the purposes of this
email.
Are you saying that the getn should not work, but indexing with the userdata
should?
M
-----Ursprüngliche Nachricht-----
Von: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]Im Auftrag von Ashwin
Hirschi
Gesendet: Sonntag, 25. April 2004 20:24
An: Lua list
Betreff: Re: userdata as table-key
> Can you use userdata as a table key?
Yes.
> I need to associate a key (into a graphical wxLua control) with data. The
key is returned as userdata.
> So I would like to say something like
>
> CtrlTable[newId] = {icnt, jcnt, kcnt}
[snip<]
>
> When I do this, and then say
> print(string.format("Size of CtrlTable = %d",
> table.getn(gCtrlTable )))
>
> The result is 0.
Well, getn() is useful if you use the table as an array, that is: store
values under the numeric keys 1, 2, 3, etc.. Since you're using the table
with non-numeric keys getn() returns 0.
> Nor can I index the table using the newId key. Where has
> the data gone?
In the example you give the table has a different name [i.e. one with a 'g'
prepended]. Could this be the cause?
Ashwin.
--
no signature is a signature