[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: userdata as table-key
- From: "Ashwin Hirschi" <deery@...>
- Date: Sun, 25 Apr 2004 20:24:17 +0200
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