eniallator

OOP Inheritance Example

Jun 7th, 2017
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.42 KB | None | 0 0
  1. local function Vehicle(wheelNum)
  2.   local Vehicle = {}
  3.   Vehicle.__wheelNum = wheelNum
  4.  
  5.   function Vehicle:getWheelNum()
  6.     return self.__wheelNum
  7.   end
  8.  
  9.   return Vehicle
  10. end
  11.  
  12. local function Car(model)
  13.   local Car = Vehicle(4)
  14.   Car.__model = model
  15.  
  16.   function Car:getModel()
  17.     return self.__model
  18.   end
  19.  
  20.   return Car
  21. end
  22.  
  23. local newCar = Car('toYODA')
  24.  
  25. print(newCar:getWheelNum())
  26. print(newCar:getModel())
Advertisement
Add Comment
Please, Sign In to add comment