lua-users home
lua-l archive

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


On 22/05/2013, at 11:13 AM, 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');

You need to pass the Aobj to fptr.  The last line should be: fptr(Aobj, 'man').

Alternatively, fun2 could be

function A:fun2()
    return function(...) return self:fun1(...) end
end

(Since you're using some class library thing, I haven't tested this code)