-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathutil.lua
More file actions
101 lines (101 loc) · 2.31 KB
/
Copy pathutil.lua
File metadata and controls
101 lines (101 loc) · 2.31 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
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
module("moonscript.util", package.seeall)
local concat = table.concat
moon = {
is_object = function(value)
return type(value) == "table" and value.__class
end,
type = function(value)
local base_type = type(value)
if base_type == "table" then
local cls = value.__class
if cls then
return cls
end
end
return base_type
end
}
pos_to_line = function(str, pos)
local line = 1
for _ in str:sub(1, pos):gmatch("\n") do
line = line + 1
end
return line
end
get_closest_line = function(str, line_num)
local line = get_line(str, line_num)
if (not line or trim(line) == "") and line_num > 1 then
return get_closest_line(str, line_num - 1)
else
return line, line_num
end
end
get_line = function(str, line_num)
for line in str:gmatch("(.-)[\n$]") do
if line_num == 1 then
return line
end
line_num = line_num - 1
end
end
reversed = function(seq)
return coroutine.wrap(function()
for i = #seq, 1, -1 do
coroutine.yield(i, seq[i])
end
end)
end
trim = function(str)
return str:match("^%s*(.-)%s*$")
end
split = function(str, delim)
if str == "" then
return { }
end
str = str .. delim
return (function()
local _accum_0 = { }
local _len_0 = 0
for m in str:gmatch("(.-)" .. delim) do
_len_0 = _len_0 + 1
_accum_0[_len_0] = m
end
return _accum_0
end)()
end
dump = function(what)
local seen = { }
local _dump
_dump = function(what, depth)
if depth == nil then
depth = 0
end
local t = type(what)
if t == "string" then
return '"' .. what .. '"\n'
elseif t == "table" then
if seen[what] then
return "recursion(" .. tostring(what) .. ")...\n"
end
seen[what] = true
depth = depth + 1
local lines = (function()
local _accum_0 = { }
local _len_0 = 0
for k, v in pairs(what) do
local _value_0 = (" "):rep(depth * 4) .. "[" .. tostring(k) .. "] = " .. _dump(v, depth)
if _value_0 ~= nil then
_len_0 = _len_0 + 1
_accum_0[_len_0] = _value_0
end
end
return _accum_0
end)()
seen[what] = false
return "{\n" .. concat(lines) .. (" "):rep((depth - 1) * 4) .. "}\n"
else
return tostring(what) .. "\n"
end
end
return _dump(what)
end