-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lua
More file actions
55 lines (47 loc) · 1.25 KB
/
utils.lua
File metadata and controls
55 lines (47 loc) · 1.25 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
54
55
local utils = {}
utils.extractDate = function(filename)
-- Pattern to match the date in the filename
local pattern = "(%d%d%d%d)%-(%d%d)%-(%d%d)"
-- Find the year, month, and day in the filename
local year, month, day = filename:match(pattern)
if year and month and day then
-- Convert these strings to numbers
year, month, day = tonumber(year), tonumber(month), tonumber(day)
-- Create a table in the format os.time expects
local dateTable = {
year = year,
month = month,
day = day,
hour = 0,
min = 0,
sec = 0
}
-- Return the os.time representation of this date
return os.time(dateTable)
end
return 0
end
-- probably unsafe for tables with loops
local deepCopy
deepCopy = function(orig)
local copy = {}
for orig_key, orig_value in next, orig, nil do
if type(orig_value) == 'table' then
copy[orig_key] = deepCopy(orig_value)
else
copy[orig_key] = orig_value
end
end
return copy
end
utils.deepCopy = deepCopy
local want
want = function (name)
local out; if xpcall(
function() out = require(name) end,
function(e) out = e end)
then return out -- success
else return nil, out end -- error
end
utils.want = want
return utils