-
Notifications
You must be signed in to change notification settings - Fork 0
/
aioruntime.lua
105 lines (99 loc) · 2.38 KB
/
aioruntime.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
local priorities = {}
local loadstring=_G.loadstring or _G.load; local preload = require"package".preload
--[[
local unpack = table.unpack or _G.unpack
local list_by_col = function()
print("preload:")
local buf = {}
local max = 5
local sizemax = 0
local hand = function(buf)
return ("%-"..(sizemax+1).."s"):rep(#buf):format(unpack(buf))
end
local keys = {}
for k in pairs(preload) do keys[#keys+1]=k end
table.sort(keys)
local all = {}
for _,k in pairs(keys) do
sizemax = (#k>sizemax) and #k or sizemax
if #buf >= max then
all[#all+1] = buf
buf = {}
end
buf[#buf+1] = k
end
if #buf > 0 then
all[#all+1] = buf
end
buf = nil
for _,g in ipairs(all) do
print(hand(g))
end
return
end
]]--
local count = function()
local KB, x = collectgarbage"count"
return ("%1.1f MB"):format( KB / 1024 ), x
end
local _M = {
add = function(name, rawcode, pri)
--print("add", name, #rawcode, pri)
local p = priorities[name]
if not preload[name] or p and (pri or 0) > p then
priorities[name] = pri or 0
if preload[name] then
print( "overwrite "..name)
end
preload[name] = function(...) return assert(loadstring(rawcode), "loadstring: "..name.." failed")(...) end
-- else
-- print( ("module %q not overwritten"):format(name), "p", p, "pri", pri )
end
end,
list = function(self)
print("preload:")
local keys = {}
for k in pairs(preload) do keys[#keys+1]=k end --("%-10s"):format(k) end
table.sort(keys)
for _,k in ipairs(keys) do
print(" - "..k)
end
--print(table.concat(keys, "\n"))
return self
end,
gcstop = function(self)
collectgarbage"stop"
print(count() )
return self
end,
gcstart = function(self)
print(count())
collectgarbage"restart"
print(count())
return self
end,
compact = function(self)
print("avant:", count() )
for k in pairs(preload) do
preload[k]=nil
end
collectgarbage("collect")
print("apres:", count() )
return self
end,
count = function(self) print( count() ) return self end,
}
return _M
--[[
local sources, priorities = {}, {}
]]--
--[[
local add
if not pcall(function() add = require"aioruntime".add end) then
local loadstring=loadstring; local preload = require"package".preload
add = function(name, rawcode)
preload[name] = function(...) return loadstring(rawcode)(...) end
end
end
for name, rawcode in pairs(sources) do add(name, rawcode, priorities[name]) end
]]--