style: Lua 统一缩进 4 空格

This commit is contained in:
Dvel
2024-02-08 18:39:49 +08:00
parent 1ffdce6a84
commit efcb4e2bdd
17 changed files with 1054 additions and 1012 deletions

View File

@@ -27,29 +27,29 @@ function metatable_chk(tab)
end
end
table.eachi = function (tab, func)
table.eachi = function(tab, func)
for i = 1, #tab do
func(tab[i], i)
end
return tab
end
table.eacha = function (tab, func)
table.eacha = function(tab, func)
for i, v in ipairs(tab) do
func(v, i)
end
return tab
end
table.each = function (tab, func)
table.each = function(tab, func)
for k, v in pairs(tab) do
func(v, k)
end
return tab
end
table.find_index = function (tab, elm, ...)
table.find_index = function(tab, elm, ...)
local _, i = table.find(tab, elm, ...)
return i
end
table.find = function (tab, elm, func)
table.find = function(tab, elm, func)
for i, v in ipairs(tab) do
if elm == v then
return v, i
@@ -57,17 +57,17 @@ table.find = function (tab, elm, func)
end
end
table.find_with_func = function (tab, elm, ...)
table.find_with_func = function(tab, elm, ...)
local i, v = table.find(tab, elm)
end
table.delete = function (tab, elm, ...)
table.delete = function(tab, elm, ...)
local index = table.find_index(tab, elm)
return index and table.remove(tab, index)
end
table.find_all = function (tab, elm, ...)
table.find_all = function(tab, elm, ...)
local tmptab = setmetatable({}, { __index = table })
local _func = (type(elm) == "function" and elm) or function (v, k, ...) return v == elm end
local _func = (type(elm) == "function" and elm) or function(v, k, ...) return v == elm end
for k, v in pairs(tab) do
if _func(v, k, ...) then
tmptab:insert(v)
@@ -77,7 +77,7 @@ table.find_all = function (tab, elm, ...)
end
table.select = table.find_all
table.reduce = function (tab, func, arg)
table.reduce = function(tab, func, arg)
local new, old = arg, arg
for i, v in ipairs(tab) do
new, old = func(v, new)
@@ -85,17 +85,17 @@ table.reduce = function (tab, func, arg)
return new, arg
end
table.map = function (tab, func)
table.map = function(tab, func)
local newtab = setmetatable({}, { __index = table })
func = func or function (v, i) return v, i end
func = func or function(v, i) return v, i end
for i, v in ipairs(tab) do
newtab[i] = func(v, i)
end
return newtab
end
table.map_hash = function (tab, func) -- table to list of array { key, v}
table.map_hash = function(tab, func) -- table to list of array { key, v}
local newtab = setmetatable({}, { __index = table })
func = func or function (k, v) return { k, v } end
func = func or function(k, v) return { k, v } end
for k, v in pairs(tab) do
newtab:insert(func(k, v))
end