Originally Posted by Seerah
You still have to define self with Frame:function() like so
Code:
Frame:function(self)
With the : notation, the frame reference is passed as the first argument (which you need to define with a variable if you wish to use it).
|
Actually, the self parameter is implied in that case. The only time you'd need to declare it specifically is if you called and/or defined it with a period instead of a colon. To quote myself from another thread:
Originally Posted by IQgryn
These four code snippets are exactly the same thing with different syntax:
Code:
function MyAddon:MyFunc(var1) print(self, var1) end
MyAddon:MyFunc("test value")
Code:
function MyAddon.MyFunc(self, var1) print(self, var1) end
MyAddon.MyFunc(MyAddon, "test value")
Code:
function MyAddon:MyFunc(var1) print(self, var1) end
MyAddon.MyFunc(MyAddon, "test value")
Code:
function MyAddon.MyFunc(self, var1) print(self, var1) end
MyAddon:MyFunc("test value")
In other words:
When defining a function, if a colon is used, self will be the first parameter (before any others you list).
When calling a function, self is automatically passed (as the first argument) with the value of whatever is before the colon when you use a colon instead of a period.
|
This is nothing specific to WoW; all of Lua works this way to make object-oriented code easier to write.