Field and method tables
- of OOP programming essentially lua using analog table to - define empty table, a class quite the Person = {} - defined fields person.name = " Kun " Person.Gender = " M " Person.Profession = " CS.GO " Person.Height = 170. - definition method Person.Speak = function () - anonymous function definition print ( " Kun build-up of so many ah " ) End function Person.Walking () - common define print ( 'Kun is Five " ) End function Person.ShowInfo () Print ( " call my personal height " ) Print ( " Height: " ..Person.Height) Print ( " Occupation: " ..Person.Profession) End - call field and method Print (person.name) Print (Person.Gender) Print (Person.Profession) Print (Person.Height) - calling method Print (Person.Speak ()) Print (Person.Walking ()) Print(Person.ShowInfo())
The introduction of local variables to reduce coupling procedure
= The Person {} - local people the Person = - defined fields person.name = " Kun " Person.Gender = " M " Person.Profession = " CS.GO " Person.Height = 170. - define methods function the Person: Speak () - the anonymous function definitions Print ( " Kun's build-up really, ah " ) End function the Person: lettin () - commonly define Print ( " Kun is Five " ) End function the Person: ShowInfo () Print ( " call my personal height " ) Print ( " Height: " ..self.Height) Print ( " Occupation: " ..self.Profession) self.Speak () self.Walking () End - to improve the function definition mode, use the self keyword (with the function uses the 'colon' defined functions) function the person: Show () Print ( " call my personal height " ) Print ( " height: " ..self.Height) Print ( " Occupation:"..self.Profession) self.Speak () self.Walking () End A = Person - will be assigned to Person A Person = nil - the destruction of Person pointers a.ShowInfo (); - continue to call the original method, However, you can call any