Skip to content

Commit ce8cdc0

Browse files
authoredMar 6, 2020
Cleanup global namespace pollution in builtin (#9451)
1 parent 9ca0b37 commit ce8cdc0

File tree

2 files changed

+57
-71
lines changed

2 files changed

+57
-71
lines changed
 

‎builtin/common/misc_helpers.lua

+1-71
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
local string_sub, string_find = string.sub, string.find
66

77
--------------------------------------------------------------------------------
8-
function basic_dump(o)
8+
local function basic_dump(o)
99
local tp = type(o)
1010
if tp == "number" then
1111
return tostring(o)
@@ -200,18 +200,6 @@ function table.indexof(list, val)
200200
return -1
201201
end
202202

203-
--------------------------------------------------------------------------------
204-
if INIT ~= "client" then
205-
function file_exists(filename)
206-
local f = io.open(filename, "r")
207-
if f == nil then
208-
return false
209-
else
210-
f:close()
211-
return true
212-
end
213-
end
214-
end
215203
--------------------------------------------------------------------------------
216204
function string:trim()
217205
return (self:gsub("^%s*(.-)%s*$", "%1"))
@@ -254,64 +242,6 @@ function math.factorial(x)
254242
return v
255243
end
256244

257-
--------------------------------------------------------------------------------
258-
function get_last_folder(text,count)
259-
local parts = text:split(DIR_DELIM)
260-
261-
if count == nil then
262-
return parts[#parts]
263-
end
264-
265-
local retval = ""
266-
for i=1,count,1 do
267-
retval = retval .. parts[#parts - (count-i)] .. DIR_DELIM
268-
end
269-
270-
return retval
271-
end
272-
273-
--------------------------------------------------------------------------------
274-
function cleanup_path(temppath)
275-
276-
local parts = temppath:split("-")
277-
temppath = ""
278-
for i=1,#parts,1 do
279-
if temppath ~= "" then
280-
temppath = temppath .. "_"
281-
end
282-
temppath = temppath .. parts[i]
283-
end
284-
285-
parts = temppath:split(".")
286-
temppath = ""
287-
for i=1,#parts,1 do
288-
if temppath ~= "" then
289-
temppath = temppath .. "_"
290-
end
291-
temppath = temppath .. parts[i]
292-
end
293-
294-
parts = temppath:split("'")
295-
temppath = ""
296-
for i=1,#parts,1 do
297-
if temppath ~= "" then
298-
temppath = temppath .. ""
299-
end
300-
temppath = temppath .. parts[i]
301-
end
302-
303-
parts = temppath:split(" ")
304-
temppath = ""
305-
for i=1,#parts,1 do
306-
if temppath ~= "" then
307-
temppath = temppath
308-
end
309-
temppath = temppath .. parts[i]
310-
end
311-
312-
return temppath
313-
end
314-
315245
function core.formspec_escape(text)
316246
if text ~= nil then
317247
text = string.gsub(text,"\\","\\\\")

‎builtin/mainmenu/pkgmgr.lua

+56
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,62 @@
1616
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1717

1818
--------------------------------------------------------------------------------
19+
local function get_last_folder(text,count)
20+
local parts = text:split(DIR_DELIM)
21+
22+
if count == nil then
23+
return parts[#parts]
24+
end
25+
26+
local retval = ""
27+
for i=1,count,1 do
28+
retval = retval .. parts[#parts - (count-i)] .. DIR_DELIM
29+
end
30+
31+
return retval
32+
end
33+
34+
local function cleanup_path(temppath)
35+
36+
local parts = temppath:split("-")
37+
temppath = ""
38+
for i=1,#parts,1 do
39+
if temppath ~= "" then
40+
temppath = temppath .. "_"
41+
end
42+
temppath = temppath .. parts[i]
43+
end
44+
45+
parts = temppath:split(".")
46+
temppath = ""
47+
for i=1,#parts,1 do
48+
if temppath ~= "" then
49+
temppath = temppath .. "_"
50+
end
51+
temppath = temppath .. parts[i]
52+
end
53+
54+
parts = temppath:split("'")
55+
temppath = ""
56+
for i=1,#parts,1 do
57+
if temppath ~= "" then
58+
temppath = temppath .. ""
59+
end
60+
temppath = temppath .. parts[i]
61+
end
62+
63+
parts = temppath:split(" ")
64+
temppath = ""
65+
for i=1,#parts,1 do
66+
if temppath ~= "" then
67+
temppath = temppath
68+
end
69+
temppath = temppath .. parts[i]
70+
end
71+
72+
return temppath
73+
end
74+
1975
function get_mods(path,retval,modpack)
2076
local mods = core.get_dir_list(path, true)
2177

0 commit comments

Comments
 (0)
Please sign in to comment.