forked from rjpcomputing/luaforwindows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.lua
More file actions
executable file
·68 lines (65 loc) · 3.32 KB
/
base.lua
File metadata and controls
executable file
·68 lines (65 loc) · 3.32 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
--------------------------------------------------------------------------------
---------------------- ## ##### ##### ###### -----------------------
---------------------- ## ## ## ## ## ## ## -----------------------
---------------------- ## ## ## ## ## ###### -----------------------
---------------------- ## ## ## ## ## ## -----------------------
---------------------- ###### ##### ##### ## -----------------------
---------------------- -----------------------
----------------------- Lua Object-Oriented Programming ------------------------
--------------------------------------------------------------------------------
-- Project: LOOP - Lua Object-Oriented Programming --
-- Release: 2.3 beta --
-- Title : Base Class Model --
-- Author : Renato Maia <[email protected]> --
--------------------------------------------------------------------------------
-- Exported API: --
-- class(class) --
-- new(class, ...) --
-- classof(object) --
-- isclass(class) --
-- instanceof(object, class) --
-- memberof(class, name) --
-- members(class) --
--------------------------------------------------------------------------------
local pairs = pairs
local unpack = unpack
local rawget = rawget
local setmetatable = setmetatable
local getmetatable = getmetatable
module "loop.base"
--------------------------------------------------------------------------------
function rawnew(class, object)
return setmetatable(object or {}, class)
end
--------------------------------------------------------------------------------
function new(class, ...)
if class.__init
then return class:__init(...)
else return rawnew(class, ...)
end
end
--------------------------------------------------------------------------------
function initclass(class)
if class == nil then class = {} end
if class.__index == nil then class.__index = class end
return class
end
--------------------------------------------------------------------------------
local MetaClass = { __call = new }
function class(class)
return setmetatable(initclass(class), MetaClass)
end
--------------------------------------------------------------------------------
classof = getmetatable
--------------------------------------------------------------------------------
function isclass(class)
return classof(class) == MetaClass
end
--------------------------------------------------------------------------------
function instanceof(object, class)
return classof(object) == class
end
--------------------------------------------------------------------------------
memberof = rawget
--------------------------------------------------------------------------------
members = pairs