-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.lua
More file actions
43 lines (39 loc) · 771 Bytes
/
utils.lua
File metadata and controls
43 lines (39 loc) · 771 Bytes
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
local charset = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
function generateId(length)
local len = length or 16
local ret = {}
local r
for i = 1, len do
r = math.random(1, #charset)
table.insert(ret, charset:sub(r, r))
end
return table.concat(ret)
end
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
function keys(t)
local keyset={}
local n=1
for k,v in pairs(t) do
keyset[n]=k
n=n+1
end
return keyset
end
function length(t)
local i = 0
for k,v in pairs(t) do
if v then i = i+1 end
end
return i
end