lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 5/23/07, Markus Heukelom <Markus.Heukelom@enterprisedynamics.com> wrote:
What is the reason this? For all other types (well, at least numbers and
strings, didn't look at others yet) you don't have to 'declare' before
usage, such as b = ""; b = "lua".

a = "" and a = "lua" are not declarations, they are assignments.
You're assigning string values to the variable 'a', which may or may
not have had a value assigned to it previously.

a = {} is assigning a table value to the variable 'a', which may or
may not have had a value assigned to it previously.

If you try to use 'a' in an expression before a value has been
assigned to it, you will likely get an error. For instance, if you say
io.write(a) before assigning a value to 'a', you'll get an error
because io.write expects a value and you passed it nil. Similarly, if
you try to index 'a' (i.e. io.write(a[1]) or a[1] = 1) before
assigning a table value to it, you'll get en error because you cannot
index nil.