lua-users home
lua-l archive

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


In message <Pine.LNX.4.30.0012111228100.17116-100000@localhost.localdomain>, Re
uben Thomas writes:
> > In section 3, you say "The form t:f(x) is syntactic sugar for t.f(t,x), whi
> ch
> > calls the method f from the table t passing the table itself as the first
> > parameter (see Section 4.5.9).".
> 
> > In section 4.5.9, you say "The statement function v:f (...) ... end is just
> > syntactic sugar for v.f = function (self, ...) ... end
> > Note that the function gets an extra formal parameter called self."
> 
> You're just confusing formal and actual parameters: if you define a function
> as:

No the manual draws the correct distinction.

> v:f () ... end
> 
> you actually get
> 
> v.f = function (self) ... end

IE the function is declared with an extra formal parameter called self.
> 
> and then when you call it with v:f(), the actual call made is v:f(v), so
> self gets set to v within f.

IE v:f() generates a call to f with an extra actual parameter (the value
of v).  This actual parameter doesn't have to be bound to the formal
parameter self.  I could declare my function:

v.f = function (a, b, c, self) ... end

Though that would probably be confusing.

Conversely, I don't have to call a function that I declared function
v:f() using the v:f() syntax.

Cheers,
 djones