lua-users home
lua-l archive

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


>This code doesn't:
>--------------------------------
>$debug
>
>myFunc = function () 
>  Test = {}
>  function Test:init() end
>end
>--------------------------------
>
>Lua says:
>  lua error: `end' expected (to close `function' at line 3);
>  last token read: `function' at line 5 in file `test.lua'

Lua 4.0 says:
error: cannot nest this kind of function declaration;
  last token read: `function' at line 5 in file `(stdin)'

So, this is a feature :-)
It might be a bad feature: it's a kind of "hand-holding", helping the user.
We think it might be a user error, as 3.2 said:
	`end' expected to close `function'.
This might happen if you really forgot the `end', as in

function myFunc()
 Test = {}

function Test:init()
end

The identation here implies a different intention by the user and there's really
an `end' missing to close `function' myFunc.

Perhaps this "hand-holding" isn't that useful...

>I thought "a:b()" was syntaxical sugar for "a.b(a)"(?)

Yes, for calls, yes. For definitions, it works only in the outer level.
--lhf