[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: why doesnt a[1] = 1 work?
- From: Thomas Lauer <thomas.lauer@...>
- Date: Wed, 23 May 2007 13:33:41 +0100
"Markus Heukelom" <Markus.Heukelom@enterprisedynamics.com> wrote:
> a = nil
> a[1]=1 -- error: indexing a nil value
>
> Yes, I understand this. I can't index anything but a table.
>
> But you could also read this as: assign a the table value {1=1}, if a is not
> of type table.
Perhaps this helps a bit: a is not a table. a is just a placeholder and
it can hold whatever you want, including a reference to a table. But if
a holds nothing (or a string or a glass of water) it can't possibly
support a statement like a[1]=1 without some behind-the-scenes magic.
However, automagically creating tables to save typing the occasional
one-liner with initialisation code doesn't sound like a must-have
feature. If something that's supposed to be a table is indeed something
else, the error that's generated by Lua may well point a developer to
some deeper flaw in his program logic.
Put differently, typing a few additional characters costs me less time
and effort than debugging. YMMV.
--
cheers thomasl
web : http://thomaslauer.com/start