object.lua 587 Bytes
Newer Older
1 2
--[[
Class model with inheritance and morphing support for Alpine Wall
3
Copyright (C) 2012-2014 Kaarle Ritvanen
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
4
See LICENSE file for license details
5 6 7 8 9 10 11 12 13
]]--


module(..., package.seeall)

function class(base)
   local cls = {}

   function cls:morph(...)
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
14
      setmetatable(self, {__index = cls})
15
      self:init(...)
16
      return self
17 18
   end

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
19 20 21 22 23 24
   local mt = {__call=function(self, ...) return cls.morph({}, ...) end}

   if not base and Object then base = Object end
   if base then mt.__index = base end

   return setmetatable(cls, mt)
25 26 27 28 29
end

Object = class()

function Object:init(...) end