~jadedctrl/gem-xwx-moe

~jadedctrl/gem-xwx-moe/gemujo_ludo/mods.niaj/fasado/subtitles/classic.lua
 ..
0 --
1 -- classic
2 --
3 -- Copyright (c) 2014, rxi
4 --
5 -- This module is free software; you can redistribute it and/or modify it under
6 -- the terms of the MIT license. See LICENSE for details.
7 --
8
9
10 local Object = {}
11 Object.__index = Object
12
13
14 function Object:new()
15 end
16
17
18 function Object:extend()
19 local cls = {}
20 for k, v in pairs(self) do
21 if k:find("__") == 1 then
22 cls[k] = v
23 end
24 end
25 cls.__index = cls
26 cls.super = self
27 setmetatable(cls, self)
28 return cls
29 end
30
31
32 function Object:implement(...)
33 for _, cls in pairs({...}) do
34 for k, v in pairs(cls) do
35 if self[k] == nil and type(v) == "function" then
36 self[k] = v
37 end
38 end
39 end
40 end
41
42
43 function Object:is(T)
44 local mt = getmetatable(self)
45 while mt do
46 if mt == T then
47 return true
48 end
49 mt = getmetatable(mt)
50 end
51 return false
52 end
53
54
55 function Object:__tostring()
56 return "Object"
57 end
58
59
60 function Object:__call(...)
61 local obj = setmetatable({}, self)
62 obj:new(...)
63 return obj
64 end
65
66
67 return Object