[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: newbie: problems in reading table from lua
- From: "Mark Meijer" <meijer78@...>
- Date: Thu, 22 Dec 2005 07:33:42 +0000
More accurately (although slightly beside the point), table.getn consider
only items numbered from 1 and up, i.e. if the table contains elements at
negatiive indices or 0, any lua array functionality (like table.getn,
ipairs(), etc) will skip those too. Which is to be expected, but it so
happens that I bumped into this the hard way recently :P
From: David Given <firstname.lastname@example.org>
Reply-To: Lua list <email@example.com>
To: Lua list <firstname.lastname@example.org>
Subject: Re: newbie: problems in reading table from lua
Date: Tue, 20 Dec 2005 19:16:06 +0000
On Tuesday 20 December 2005 19:20, Alexander Miro wrote:
> // the next function will return 0 (zero).
> // It should return 2 (two).... WHY NOT???
Because getn only works on tables used as arrays, not tables used as
associative arrays, I'm afraid.
A table may contain some *numbered* items, and some *names* items.
table.getn() (and the low-level luaL_getn()) both consider only the
items. In order to extract the names items you'll need to iterate through
table using lua_next().
+- David Given --McQ-+
| email@example.com | UN-altered REPRODUCTION and DISSEMINATION of this
| (firstname.lastname@example.org) | IMPORTANT information is ENCOURAGED
+- www.cowlark.com --+
<< attach3 >>