lua syntax q

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

lua syntax q

Max Ischenko
Can someone explain me why

Services.ctl.start = function (service)
	return 0
end

works fine, while

function Services.ctl.start(service)
	return 0
end
	
gets parse error.

PS: I have
Services = {}
Services.ctl = {}

defined

-- 
The Best Things In Life Are Free.
                   -- ESR.

Reply | Threaded
Open this post in threaded view
|

Re: lua syntax q

Steve Dekorte-4
Max Ischenko wrote:
> Services.ctl.start = function (service) ...
> works fine, while 
>  
> function Services.ctl.start(service) ...
> gets parse error. 

Are you doing this within a function definition?
Lua won't let you define a named function from within a function.

Steve

Reply | Threaded
Open this post in threaded view
|

Re: lua syntax q

Luiz Henrique de Figueiredo
In reply to this post by Max Ischenko
>Lua won't let you define a named function from within a function.

This restriction was removed in Lua 4.0.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: lua syntax q

Max Ischenko
	Hi there, Luiz Henrique de Figueiredo!
	On Tuesday, 26 of December you wrote:

> >Lua won't let you define a named function from within a function.
> 
> This restriction was removed in Lua 4.0.

Here is sample code chunk:


$ lua test.lua 
error: `(' expected;
  last token read: `.' at line 3 in file `test.lua'
$ cat test.lua
Foo={}
Foo.Bar={}
function Foo.Bar.fun(arg)
        print(arg)
end

Foo.Bar.fun('Hello!')


Comments?

-- 
Best regards, Maxim F. Ischenko.

Reply | Threaded
Open this post in threaded view
|

Re: lua syntax q

Luiz Henrique de Figueiredo
In reply to this post by Max Ischenko
>> >Lua won't let you define a named function from within a function.
>> 
>> This restriction was removed in Lua 4.0.
>
>function Foo.Bar.fun(arg)
>error: `(' expected;
>  last token read: `.' at line 3 in file `test.lua'

I meant that in Lua 4.0 you can write

function a()
  function b()
   ...
  end
end

The restrictions on what expressions may appear after "function" are still
in place.
--lhf