[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ideas about colon operator syntax (and a patch in the work)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 1 May 2014 21:33:54 +0200
2014-05-01 19:50 GMT+02:00 Thomas Jericke <tjericke@indel.ch>:
> I am not so sure if I would implement it this way. Just as a Gedankenexperiment,
> if methods would be first class citizen of Lua it would mean that the function itself
> would know that it is a method or a static function.
>
> So if you write:
> table = {}
> function table:f ()
> ....
> end
>
> f would contain a internal reference to table. So local b = table.f would contain that
> reference as well and b() would call f with table as first parameter.
That's a totally different paradigm. The colon in Lua is sugar for
sugar for sugar.
function table:f (...)
is sugar for
function table.f (self,...)
which is sugar for
table.f = function(self,...)
which is sugar for
table["f"] = function(self,...)
So f receives a local reference to the object, not a reference to the prototype.