Pop.Box/tmp.class.usage.lua
2017-08-14 06:02:36 -07:00

25 lines
545 B
Lua

local class = require "class"
local Car, CarBase = class("Car")
function Car:__init(x, y)
self.x = x or 0
self.y = y or 0
end
function CarBase:print() -- this will be correct
print("I'm a car, at ("..self.x..","..self.y..")")
end
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