lua-users home
lua-l archive

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

If Lua complained out of pure spite for the long and unreadable line
it was asked to parse, I wouldn't be surprised ;-)

If I'm looking at this correctly, the issue can be reduced to this
(I'm guessing you knew this already):

print("Statement 1");(false or print)("Statement 2")

In this case, if I omit the semicolon, Lua complains about an attempt
to call a nil value. Makes sense. It may become more difficult to
interpret the error report, if the return value of Statement 1 is
something callable. Personally, I always end my statements with a
semi-colon. It's a paranoia thing, I guess, but evidently not entirely
unwarranted :-o


2009/2/18 Eike Decker <>:
> Hi
> I was writing some small piece of code, testing a bit the syntax features
> (with the aim of reducing the number of lines of code) of Lua when I
> suddenly struggled in total surprise - after years of Lua programming: My
> code needed a semicolon ( ; ). This has never happened to me before.
> The Lua syntax check did complain absolutely correctly and in my opinion
> this piece of code is not really nice and I think I am not going to use it
> - yet it is maybe a quite nice example for what can happen and when a ; is
> necessary in Lua code:
>   local info = debug.getinfo(2)
>   local msg = ("%s{%d} = %s (%s:%d)\n"):format( or
> "unnamed",,
>     (",%s"):rep(#self):sub(2):format(unpack(self)),
> info.source,info.currentline); -- needing the ;
>   (file or io.stdout):write(msg)
> I don't know how it happens that I never experienced such a case before,
> but I found it quite interesting...
> Eike