[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ambigous function call (or: my first ";" in Lua)
- From: Mark Meijer <meijer78@...>
- Date: Wed, 18 Feb 2009 10:41:16 +0100
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
Regards,
Mark
2009/2/18 Eike Decker <eike@cube3d.de>:
> 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(self.name or
> "unnamed",self.id,
> (",%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
>