honeylisp/vendor/lite/data/core/object.lua
Jeremy Penner 3d52b70bbc git subrepo clone https://github.com/jeremypenner/lite.git vendor/lite
subrepo:
  subdir:   "vendor/lite"
  merged:   "2783adc"
upstream:
  origin:   "https://github.com/jeremypenner/lite.git"
  branch:   "master"
  commit:   "2783adc"
git-subrepo:
  version:  "0.4.2"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "65fde50"
2020-11-19 15:40:36 -05:00

59 lines
819 B
Lua

local Object = {}
Object.__index = Object
function Object:new()
end
function Object:extend()
local cls = {}
for k, v in pairs(self) do
if k:find("__") == 1 then
cls[k] = v
end
end
cls.__index = cls
cls.super = self
setmetatable(cls, self)
return cls
end
function Object:implement(...)
for _, cls in pairs({...}) do
for k, v in pairs(cls) do
if self[k] == nil and type(v) == "function" then
self[k] = v
end
end
end
end
function Object:is(T)
local mt = getmetatable(self)
while mt do
if mt == T then
return true
end
mt = getmetatable(mt)
end
return false
end
function Object:__tostring()
return "Object"
end
function Object:__call(...)
local obj = setmetatable({}, self)
obj:new(...)
return obj
end
return Object