Originally Posted by Billtopia
I see what you are saying there... that when defining a method it adds the 'self' variable in before the function variables... I was thinking that it did it by setting the first variable to self
|
Kindof, but it's important (or maybe not) to know that doing it that way is in no way magical. All that happens is that the first parameter is hidden and is called
self. It doesn't have to refer to any frame at all. That's just the normal usage of it.
You could do this if you wanted:
Code:
local t = {}
function t:print()
print(self)
end
function t.print(blarg) -- these functions work exactly the same, but this one doesn't use colon syntax, so the parameter must be explicitly defined
print(blarg)
end
t:print() -- when calling a function using colon syntax it automatically passes the table in question as the first argument (and "hides" it), so this will print the table t
t.print("hax") -- regular syntax, no hidden arguments will be passed