-
Notifications
You must be signed in to change notification settings - Fork 0
/
drop.lua
35 lines (29 loc) · 1.05 KB
/
drop.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
-- drop/restore
require "pageutil"
require "tableutil"
function drop(pagenumber)
local id = assert(page.drop(pagenumber))
table.remove(info.releasepages, table.linersearch(info.releasepages, pagenumber))
table.insert(info.droppages, {origin = pagenumber, id = id})
table.sort(info.droppages, function (a, b)
-- <
return a.origin < b.origin
end)
end
function restore(pageid, failsafe)
local i = table.linersearch(info.droppages, {id = pageid}, function (tv, sv)
return tv.id == sv.id
end)
if i == nil then error("restore 失敗: 理由: 与えられた id が見つからない") end
local dropinfo = info.droppages[i]
-- 安全に戻せるか?
if table.linersearch(info.releasepages, dropinfo.origin) ~= nil then
failsafe(dropinfo.origin)
end
-- 戻す
assert(page.restore(dropinfo))
-- テーブルを更新
table.remove(info.droppages, table.linersearch(info.droppages, dropinfo))
table.insert(info.releasepages, dropinfo.origin)
table.sort(info.releasepages)
end