If that class would be singleton (only one instance across whole application), then it would create only one function. However it is still better to use self.Foo = function(
self ) so you don't have to remember whether you must call it with "." or ":" and always call every function on instance with ":". Also I'm not saying that you shouldn't create functions with "." operator, I'm talking about creating functions inside of function (which is not always bad.. sometimes it's neccessary, but if you don't have to then don't do it) and using always "self" when that function is going to be member of class.
Code:
Foo = class();
Foo.Constructor = function( self )
end
Foo.Bar = function( self, arg )
end
is exactly the same as
Code:
Foo = class();
function Foo:Constructor = function()
end
function Foo:Bar( arg )
end
and would work same as
Code:
Foo = class();
function Foo:Constructor()
self.Bar = function( self, arg )
end
end
or
Code:
Foo = class();
function Foo:Constructor()
function self:Bar( arg )
end
end
but the last 2 would eat more memory than the first 2 after creating more than 1 instance. The difference is small, but when you put 10000 small things together, they make one big thing so it's good to know how things work (try this
http://www.lua.org/pil/16.html#ObjectSec )
Events are different thing. You need to do it like this, because you are changing function on another instance - so function foo:MouseClick( args ) would work too, just "sender" would be named "self" and you would loose "self" reference from parent scope.
Also note that lua has no support for events, so what we call events are just plain functions.