Pop.Box/tmp.class.usage.lua

25 lines
545 B
Lua
Raw Permalink Normal View History

local class = require "class"
2017-08-14 12:48: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
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
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