"." Use of:
Tsprite = { 0, 0, } function Tsprite.setposition (M, x, y) = x; = y end local who = tsprite
Tsprite = Nil 12) print(who.x, WHO.Y)
--Output: 1 2
Usage of ":"
Tsprite = { 0, 0, } function Tsprite:setposition (x, y)-different = x; = y end local who = tsprite
Tsprite = nil who:setposition (12)--only this differs from print(who.x , WHO.Y)
--Output: 1 2
Do you see the difference? Yes, there's a missing caller parameter.
Who.setposition (who, 1, 2)
Who:setposition (1, 2)
Use the ":" equivalent to automatically enter the caller's parameter, either: the front table. ---Self is the default parameter hidden in LUA--the caller
and ":" This usage is mostly used in Lua's "class" usage, because after using ":", you can think of Tsprite as a class, and SetPosition () is Tsprite member method, but he needs to be in the outside definition of the class.
Lua about "." The difference between the usage and the ":" Sign