[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Simple question about traversing a table
- From: David Kolf <kolf@...>
- Date: Tue, 21 Jun 2011 15:47:03 +0200
Christophe Jorssen wrote:
First of all, I'm quite new to lua so forgive me if
- this is a silly question,
- this is not the right place to ask such a silly question.
I guess this is the right place to ask such a question.
I have the following code.
if t then
for k=1,#t do
if type(t[k] == "table") then
Here is the mistake, the parenthesis are wrong. I guess you want
if type(t[k]) == "table" then
Otherwise Lua would first evaluate the equation t[k] == "table" which
would return 'false' or 'true'. 'false' or 'true' is then passed to
'type' which would return the string "boolean". And a string (or any
other value except false or nil) counts as true when used in an
print("not a table")