forked from rjpcomputing/luaforwindows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.lua
More file actions
executable file
·75 lines (72 loc) · 3.53 KB
/
simple.lua
File metadata and controls
executable file
·75 lines (72 loc) · 3.53 KB
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
65
66
67
68
69
70
71
72
73
74
75
--------------------------------------------------------------------------------
---------------------- ## ##### ##### ###### -----------------------
---------------------- ## ## ## ## ## ## ## -----------------------
---------------------- ## ## ## ## ## ###### -----------------------
---------------------- ## ## ## ## ## ## -----------------------
---------------------- ###### ##### ##### ## -----------------------
---------------------- -----------------------
----------------------- Lua Object-Oriented Programming ------------------------
--------------------------------------------------------------------------------
-- Project: LOOP - Lua Object-Oriented Programming --
-- Release: 2.3 beta --
-- Title : Simple Inheritance Class Model --
-- Author : Renato Maia <[email protected]> --
--------------------------------------------------------------------------------
-- Exported API: --
-- class(class, super) --
-- new(class, ...) --
-- classof(object) --
-- isclass(class) --
-- instanceof(object, class) --
-- memberof(class, name) --
-- members(class) --
-- superclass(class) --
-- subclassof(class, super) --
--------------------------------------------------------------------------------
local require = require
local rawget = rawget
local pairs = pairs
local table = require "loop.table"
module "loop.simple"
--------------------------------------------------------------------------------
local ObjectCache = require "loop.collection.ObjectCache"
local base = require "loop.base"
--------------------------------------------------------------------------------
table.copy(base, _M)
--------------------------------------------------------------------------------
local DerivedClass = ObjectCache {
retrieve = function(self, super)
return base.class { __index = super, __call = new }
end,
}
function class(class, super)
if super
then return DerivedClass[super](initclass(class))
else return base.class(class)
end
end
--------------------------------------------------------------------------------
function isclass(class)
local metaclass = classof(class)
if metaclass then
return metaclass == rawget(DerivedClass, metaclass.__index) or
base.isclass(class)
end
end
--------------------------------------------------------------------------------
function superclass(class)
local metaclass = classof(class)
if metaclass then return metaclass.__index end
end
--------------------------------------------------------------------------------
function subclassof(class, super)
while class do
if class == super then return true end
class = superclass(class)
end
return false
end
--------------------------------------------------------------------------------
function instanceof(object, class)
return subclassof(classof(object), class)
end