2017-08-14 13:02:36 +00:00
|
|
|
local class = require "class"
|
2017-08-14 12:48:36 +00:00
|
|
|
|
2017-08-14 13:02:36 +00:00
|
|
|
local Car, CarBase = class("Car")
|
2017-08-14 12:48:36 +00:00
|
|
|
|
|
|
|
function Car:__init(x, y)
|
|
|
|
self.x = x or 0
|
|
|
|
self.y = y or 0
|
|
|
|
end
|
|
|
|
|
2017-08-14 13:02:36 +00:00
|
|
|
function CarBase:print() -- this will be correct
|
2017-08-14 12:48:36 +00:00
|
|
|
print("I'm a car, at ("..self.x..","..self.y..")")
|
|
|
|
end
|
2017-08-14 13:02:36 +00:00
|
|
|
|
|
|
|
local Motorcycle, MotorcycleBase = class("Motorcycle", Car)
|
|
|
|
|
|
|
|
function Motorcycle:__init(x, y)
|
|
|
|
Car.__init(self, x, y) -- if you want to use a parent's constructor, you must manually call it
|
|
|
|
|
|
|
|
-- do additional stuff or whatever
|
|
|
|
end
|
|
|
|
|
|
|
|
function MotorcycleBase:someFunc()
|
|
|
|
-- do whatever to an instance
|
|
|
|
end
|