lua-users home
lua-l archive

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


On Tue, May 21, 2013 at 4:13 PM, Muqtheear S <muqtheear.s@gmail.com> wrote:
> Hi all,
>         When I execute below code, fun1 is getting called, but val is always
> nil(supposed to be 'man'). Please suggest me
>
> class.A()
> function A:fun1(val)
>     print(val)
> end
> function A:fun2()
>     return self.fun1;
> end
> Aobj = A()--creating an object
> fptr = Aobj:fun2()
> fptr('man');
>
>
> Thanks & Regards,
> Muqtheear.S

This isn't Javascript. Lua doesn't have the concept of bound
functions. Specifically:

> fptr = Aobj:fun2()

This makes fptr reference the function "fun2(self)", not the function
"Aobj.fun2()".

/s/ Adam