[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Function Pointers?
- From: "Nick Trout" <nick@...>
- Date: Fri, 16 Nov 2001 19:08:11 -0000
> One more question on the topic...in the below listing, the call gl.a()
> works, but the call gl.b(1) produces an error, saying that "t" is
> nil...looks like the parameter is not being passed. How do I get around
> that?
>
> tab = {}
>
> function tab:test1()
> print ("Hello from test1")
> end
>
> function tab:test2(t)
> print ("Hello from test2 " .. t)
> end
>
> gl =
>
> a = tab.test1,
> b = tab.test2
> }
>
> gl.a()
> gl.b(1)
Hi John,
gl.b(1) fails because it should be gl:b(1) ie. not the : not . This adds
"self" so tab:test2 can reference itself through the variable "self" (if
youve used Python, you have declare self yourself!).
There is lots of sample code on the wiki if you'd like to take a stroll:
http://lua-users.org/wiki/SampleCode
Regards,
Nick