-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysapi-mod.lua
More file actions
53 lines (49 loc) · 1.08 KB
/
sysapi-mod.lua
File metadata and controls
53 lines (49 loc) · 1.08 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
setfenv(1, require "sysapi-ns")
local tinsert, tsort = table.insert, table.sort
local pairs, setmetatable = pairs, setmetatable
SysapiMod =
setmetatable(
{
all = {},
getAll = function(self)
local res = ""
local names = {}
for name in pairs(self.all) do
tinsert(names, name)
end
tsort(names)
for i = 1, #names do
res = res .. tostring(self.all[names[i]])
end
return res
end
},
{
__call = function(self, name)
local mod =
setmetatable(
{
name = name
},
{
__tostring = function(self)
local fields = {}
local res = self.name .. "\n"
for field in pairs(self) do
if field ~= "name" then
tinsert(fields, field)
end
end
tsort(fields)
for _, field in pairs(fields) do
res = res .. " " .. field .. "\n"
end
return res
end
}
)
self.all[name] = mod
return mod
end
}
)