lua-users home
lua-l archive

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


Replace dot with colon mytab:func1()
For example,

local mytab = {
    k = 5;
    func1 = function(self, a) print(self.k + a) end;
    func2 = function(self, m) print(self.k * m) end;
}

mytab:func1(5) -- 10
mytab:func2(3) -- 15



2013/8/23 Philipp Kraus <philipp.kraus@tu-clausthal.de>
Hello,

I'm using something like this

mytab = {

    func1 = function(…) do something end
    func2 = function(…) do something other

}


I can call the functions with mytab.func1(), but I would like to use a reference to the table itself (like the self parameter on Python classes):
mytab = {

    func1 = function(self, …) do something end
    func2 = function(self, …) do something other

}

and self should be point to mytab. How can I do this?
Thanks a lot

Phil



--
С уважением,
инженер-программист ООО "СТ-ПРЕМИУМ"
Рафис Ганеев
+79257371586
rafisganeyev@gmail.com