lua-users home
lua-l archive

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


Markus Heukelom wrote:

a[1]=1

does result is a compilation error?

My guess is it is to avoid ambiguities in the syntax,

Perhaps a minor point, but note that this is a runtime
error, not a compilation error; it doesn't have to do with
syntax:

 > function f()
 >>   a[1] = 1
 >> end
 > f()
 stdin:2: attempt to index global 'a' (a nil value)
 stack traceback:
         stdin:2: in function 'f'
         stdin:1: in main chunk
         [C]: ?

Apart from wrapping the statement in a function to separate
compilation and runtime, another way to tell a compile error
from a runtime error is that the former lacks a stack
traceback:

 > foo = = bar
 stdin:1: unexpected symbol near '='

Also note (sorry if someone else has already pointed this
out) that there's an idiom for creating a table only if
there isn't one already:

 > t = t or {}

--
Aaron
http://arundelo.com/