In Lua development, we often confuse the differences between the two. Below is an example to explain:
1 class = {} 2 class. _ Index = Class 3 4 function class. new (x, y) 5 Local CLS ={} 6 setretriable (CLS, class) 7 Cls. X = x 8 Cls. y = y 9 return cls10 end11 function class: Test () 12 -- equivalent to 13 -- function class. test (Self) 14 print (self. x, self. y) 15 end16 17 18 object = Class. new (10, 20) 19 20 object: Test () 21 -- equivalent to 22 object. test (object)
You can see:
1. When defined: Class: Test () and class. test (Self) is equivalent, point number (.) to achieve the colon (:) effect, add a self parameter to the first parameter;
2. When calling: object: Test () is equivalent to object. Test (object). The vertex (.) must add the object itself to the first parameter.
Conclusion: You can view the dot (.) as a static method, and the colon (:) As a member method.