lua-users home
lua-l archive

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


> Why do we have this restriction in Lua?  Shouldn't "function var(...)"
> just be sugar for "var = function(...)"?

It is too complicated to do the "full sugar". For instance, you can write

  foo(x,y,z).x = function (a,b,c) end

But if you try

  function foo(x,y,z).x (a,b,c)
  end

the parser would have a hard time to realize that (x,y,z) is not the
parameter list of the function.

With the options Lua gives you, you can always "factor out" the prefix
and use the sugar, like this:

  obj = foo(x,y,z)

  function obj.x (a,b,c)
  end

-- Roberto