/
GeyserUtil.lua
60 lines (55 loc) · 1.48 KB
/
GeyserUtil.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
--------------------------------------
-- --
-- The Geyser Layout Manager by guy --
-- --
--------------------------------------
--- Generate a window name unique to this session.
function Geyser.nameGen (type)
local index = Geyser.i
local t = type or "window"
Geyser.i = Geyser.i + 1
return "anon_" .. t .. "_" .. index
end
--- Hide all managed windows.
function Geyser.hideAll(type)
for _, v in pairs(Geyser.windowList) do
if v.type == type or not type then
v:hide()
end
end
end
--- Show all managed windows.
function Geyser.showAll(type)
for _, v in pairs(Geyser.windowList) do
if v.type == type or not type then
v:show()
end
end
end
--- Non-recursive display of an item, because the normal 'display' was
-- causing Mudlet to hang. Not sure why.
function Geyser.display (table)
echo("------ " .. type(table) .. " ------\n")
if type(table) == "table" then
for k, v in pairs(table) do
echo("'" .. tostring(k) .. "' - " .. tostring(v) .. "\n")
end
else
echo(tostring(table) .. "\n")
end
end
--- Clone a table, for good fun and profit.
function Geyser.copyTable (table)
local copy = {}
if table then
for k, v in pairs(table) do
-- do deep copy on a table if it requests one by having the __clone function defined.
if type(v) == "table" and v.__clone then
copy[k] = v.__clone()
else
copy[k] = v
end
end
end
return copy
end