forked from rxi/classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassic.lua
64 lines (56 loc) · 1.19 KB
/
classic.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
--
-- classic
--
-- forked from rxi/classic
--
-- A tiny class module for Picotron and PICO-8.
--
-- Copyright (c) 2025, ahai64
--
-- This module is free software; you can redistribute it and/or modify it under
-- the terms of the MIT license. See LICENSE for details.
--
local Object = {}
Object.__index = Object
function Object:new(...)
end
function Object:extend()
local claass = {}
for k, v in pairs(self) do
if k[1] == '_' and k[2] == '_' then
claass[k] = v
end
end
claass.__index = claass
claass.super = self
setmetatable(claass, self)
return claass
end
function Object:implement(...)
for _, claass in pairs({ ... }) do
for k, v in pairs(claass) 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