WoW:Object-oriented programming: Difference between revisions

m
(Actually just reverting to Apr 5 revision. Too much is wrong. See discussion page.)
Line 245: Line 245:
   end
   end


== Notes ==
Calling a member function using the dot operator (.) will '''not''' implicitly pass the parent table to the function.
local table = {
    msg = "Hello World",
    func = function(self, a, b, c)
        print(self.msg)
        print(a)
        print(b)
        print(c)
    end,
}
table.func(1,2,3) -- Results in the error, "attempt to index local 'self' (a nil value)"
table:func(1,2,3) -- Results in the expected:
-- Output --
"Hello World"
1
2
3
[[Category:Interface Customization]]
[[Category:Interface Customization]]
[[Category:Glossary]]
[[Category:Glossary]]
[[Category:Guides]]
[[Category:Guides]]
[[Category:Lua functions| Object Oriented Programming]]
[[Category:Lua functions| Object Oriented Programming]]
Anonymous user