parsav  Diff

Differences From Artifact [c868f8cd22]:

To Artifact [31fe76fcd7]:


20
21
22
23
24
25
26











































27
28
29
30
31
32
33
34
..
37
38
39
40
41
42
43







44

45
46
47
48

49
50
51
52
53
54
55
..
68
69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
..
94
95
96
97
98
99
100
101
102



103
104
105
106
107
108
109
110
111
	if val then return os.execute(cmd) else
		local fd = io.popen(cmd,'r')
		local t = fd:read('*a')
		return chomp(t), fd:close()
	end
end












































local function dump(v,pfx,cyc)
	pfx = pfx or ''
	cyc = cyc or {}
	local np = pfx .. '  '

	if type(v) == 'table' then
		if cyc[v] then return '<...>' else cyc[v] = true end
	end
................................................................................
		return string.format('%q', v)
	elseif type(v) == 'table' then
		local str = ''
		for k,v in pairs(v) do
			local tkey, tval = dump(k,np,cyc), dump(v,np,cyc)
			str = str .. string.format('%s[%s] = %s\n', np, tkey,tval)
		end







		return '{\n' .. str .. pfx .. '}\n'

	else
		return string.format('%s', v)
	end
end

local ping = function(path)
	local f = io.open(path)
	if f then f:close() return true end
	return false
end
local tobool = function(s)
	if s == true then return true
................................................................................
	local seed = 1 for i = 1, 8 do
		seed = seed * string.byte(string.sub(ent,i,i))
	end
	math.randomseed(seed)
else math.randomseed(os.time()) end

return {
	exec = exec;
	dump = dump;
	ping = ping;
	chomp = chomp;
	map = map;

	tobool = tobool;
	find = function(lst,pred)
		for k,v in pairs(lst) do
			local test = pred(v,k) 
			if test then return test end
		end
		return nil
	end;
................................................................................
			s = s .. string.char(ofs) 
		end
		return s
	end;
	append = function(a,b)
		for _, v in pairs(b) do a[#a+1] = v end
	end;
	has = function(haystack,needle,eq)
		eq = eq or function(a,b) return a == b end



		for k,v in pairs(haystack) do
			if eq(needle,v) then return k end
		end
	end;
	keys = function(ary)
		local kt = {}
		for k,v in pairs(ary) do kt[#kt+1] = k end
		return kt
	end;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|







 







>
>
>
>
>
>
>
|
>




>







 







<

|
<
<
>
|







 







|
|
>
>
>

|







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
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
120
121
122
123
124
125
126

127
128


129
130
131
132
133
134
135
136
137
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
	if val then return os.execute(cmd) else
		local fd = io.popen(cmd,'r')
		local t = fd:read('*a')
		return chomp(t), fd:close()
	end
end

local function copy(a)
	local new = {}
	for k,v in pairs(a) do new[k] = v end
	return new
end

local function cat(a,b)
	a = copy(a)
	local ofs = #a
	for k,v in pairs(b) do
		if type(k) == 'number' then
			a[k+ofs] = v
		else a[k] = v end
	end
	return a
end

local function search(tbl,pred,lst,path)
	lst = lst or {} path = path or {}
	if type(pred) ~= 'function' then
		local val = pred
		pred = function(a,k)
			if type(a) == 'table' and a ~= val then return end
			return a == val
		end
	end
	for k,v in pairs(tbl) do
		local res = pred(v,k)
		local np = cat(path, {tbl})
		if res == true then
			table.insert(lst, {
				key = k;
				value = v;
				parent = tbl;
				path = np;
			})
		elseif res == nil then
			search(v,pred,lst,np)
		end
	end
	return lst
end

local function dump(v,pfx,cyc,ismeta)
	pfx = pfx or ''
	cyc = cyc or {}
	local np = pfx .. '  '

	if type(v) == 'table' then
		if cyc[v] then return '<...>' else cyc[v] = true end
	end
................................................................................
		return string.format('%q', v)
	elseif type(v) == 'table' then
		local str = ''
		for k,v in pairs(v) do
			local tkey, tval = dump(k,np,cyc), dump(v,np,cyc)
			str = str .. string.format('%s[%s] = %s\n', np, tkey,tval)
		end
		local meta = ''
		if getmetatable(v) then
			meta = dump(getmetatable(v),pfx,cyc,true) .. '::'
		end
		if ismeta then
			return string.format('%s<|\n%s%s|>',meta,str,pfx)
		else
			return meta..'{\n' .. str .. pfx .. '}\n'
		end
	else
		return string.format('%s', v)
	end
end

local ping = function(path)
	local f = io.open(path)
	if f then f:close() return true end
	return false
end
local tobool = function(s)
	if s == true then return true
................................................................................
	local seed = 1 for i = 1, 8 do
		seed = seed * string.byte(string.sub(ent,i,i))
	end
	math.randomseed(seed)
else math.randomseed(os.time()) end

return {

	dump = dump;
	exec = exec, ping = ping;


	map = map, copy = copy, cat = cat, search = search;
	chomp = chomp, tobool = tobool;
	find = function(lst,pred)
		for k,v in pairs(lst) do
			local test = pred(v,k) 
			if test then return test end
		end
		return nil
	end;
................................................................................
			s = s .. string.char(ofs) 
		end
		return s
	end;
	append = function(a,b)
		for _, v in pairs(b) do a[#a+1] = v end
	end;
	has = function(haystack,pred)
		if type(pred) ~= 'function' then
			local val = pred
			pred = function(a) return a == val end
		end
		for k,v in pairs(haystack) do
			if pred(v,k) then return k,v end
		end
	end;
	keys = function(ary)
		local kt = {}
		for k,v in pairs(ary) do kt[#kt+1] = k end
		return kt
	end;