Site Notice
hello, world
Difference between revisions of "Module:Util"
From Project-EPB Commons
([InPageEdit] 没有编辑摘要) |
([InPageEdit] 没有编辑摘要) |
||
Line 3: | Line 3: | ||
-- 获取表长度 | -- 获取表长度 | ||
− | function p. | + | function p.tableLength(tbl) |
local length = 0 | local length = 0 | ||
for k, v in pairs(tbl) do | for k, v in pairs(tbl) do |
Revision as of 00:02, 11 April 2020
Documentation for this module may be created at Module:Util/doc
-- 常用Lua工具集
local p = {}
-- 获取表长度
function p.tableLength(tbl)
local length = 0
for k, v in pairs(tbl) do
length = length + 1
end
return length
end
-- 返回表中含有value值的key
function p.valueInTable(tbl, value)
local final = {}
for k, v in pairs(tbl) do
if v == value then
final[k] = v
end
end
return final
end
return p