[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question about __index and classes
- From: Dirk Laurie <dpl@...>
- Date: Sun, 28 Aug 2011 09:21:33 +0200
On Sun, Aug 28, 2011 at 05:20:13AM +0200, Should Pain wrote:
> I would just say one more setence.
I would add three remarks about defining with the colon notation.
At the definition stage, you are allowed
function a:fct(...)
-- automatically defines 'self' as first arg; if you refer to 'a'
-- inside, it is the global 'a', not the first arg.
which is syntactic sugar for
function a.fct(self,...)
-- 'self' is the first arg, if you refer to 'a' inside, it is the
-- global 'a', not the object.
not for
function a.fct(a,...)
-- 'self' is the global 'self'
You are not allowed
a:fct = function(...)
although
a.fct = function(self,...)
is legal.
Finally, even if you defined a function via colon notation, e.g:
a = {}
function a:fct()
print(self)
end
there is nothing object-oriented about the function.
fx = a.fct
fx "Hello" --> Hello
Dirk