diff options
-rw-r--r-- | script-beta/fs-utility.lua | 6 | ||||
-rw-r--r-- | script-beta/utility.lua | 56 |
2 files changed, 62 insertions, 0 deletions
diff --git a/script-beta/fs-utility.lua b/script-beta/fs-utility.lua index 40a939ce..42041734 100644 --- a/script-beta/fs-utility.lua +++ b/script-beta/fs-utility.lua @@ -385,6 +385,9 @@ local function fileRemove(path, optional) end local function fileCopy(source, target, optional) + if optional.onCopy and optional.onCopy(source, target) == false then + return + end local isDir1 = fsIsDirectory(source, optional) local isDir2 = fsIsDirectory(target, optional) local isExists = fsExists(target, optional) @@ -415,6 +418,9 @@ local function fileCopy(source, target, optional) end local function fileSync(source, target, optional) + if optional.onSync and optional.onSync(source, target) == false then + return + end local isDir1 = fsIsDirectory(source, optional) local isDir2 = fsIsDirectory(target, optional) local isExists = fsExists(target, optional) diff --git a/script-beta/utility.lua b/script-beta/utility.lua index bffefec9..75c04e71 100644 --- a/script-beta/utility.lua +++ b/script-beta/utility.lua @@ -13,6 +13,7 @@ local mathType = math.type local mathCeil = math.ceil local getmetatable = getmetatable local mathAbs = math.abs +local mathRandom = math.random local ioOpen = io.open local utf8Len = utf8.len local mathHuge = math.huge @@ -468,4 +469,59 @@ function m.utf8Len(str, start, finish) return 1 + m.utf8Len(str, start, pos-1) + m.utf8Len(str, pos+1, finish) end +function m.revertTable(t) + local len = #t + if len <= 1 then + return t + end + for x = 1, len // 2 do + local y = len - x + 1 + t[x], t[y] = t[y], t[x] + end + return t +end + +function m.randomSortTable(t, max) + local len = #t + if len <= 1 then + return t + end + if not max or max > len then + max = len + end + for x = 1, max do + local y = mathRandom(len) + t[x], t[y] = t[y], t[x] + end + return t +end + +function m.tableMultiRemove(t, index) + local mark = {} + for i = 1, #index do + local v = index[i] + mark[v] = true + end + local offset = 0 + local me = 1 + local len = #t + while true do + local it = me + offset + if it > len then + for i = me, len do + t[i] = nil + end + break + end + if mark[it] then + offset = offset + 1 + else + if me ~= it then + t[me] = t[it] + end + me = me + 1 + end + end +end + return m |