Module:Explode String: Difference between revisions
From Valheim Wiki
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
---Holds the arguments from the template call. | ---Holds the arguments from the template call. | ||
local args_table | local args_table | ||
local function spliton(input, sep) | |||
if sep == nil then | |||
sep = "," | |||
end | |||
local t = {} | |||
for str in string.gmatch(input, "([^"..sep.."]+)") do | |||
table.insert(t, str) | |||
end | |||
return t | |||
end | |||
---Return a trimmed version of the value of the template parameter with the specified `key`. | ---Return a trimmed version of the value of the template parameter with the specified `key`. | ||
| Line 10: | Line 22: | ||
---@return string|nil | ---@return string|nil | ||
local function getArg(key) | local function getArg(key) | ||
local value = args_table[key] | local value = args_table[key] | ||
if not value then | if not value then | ||
return nil | return nil | ||
end | end | ||
value = trim(value) | value = trim(value) | ||
if value == '' then | if value == '' then | ||
return nil | return nil | ||
end | end | ||
return value | return value | ||
end | end | ||
| Line 31: | Line 44: | ||
mw.log(ret) | mw.log(ret) | ||
return | return spliton(getArg('input')) | ||
end | end | ||
return p | return p | ||
Revision as of 21:41, 18 February 2021
Documentation for this module may be created at Module:Explode String/doc
local currentFrame
local trim = mw.text.trim
---Holds the arguments from the template call.
local args_table
local function spliton(input, sep)
if sep == nil then
sep = ","
end
local t = {}
for str in string.gmatch(input, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
---Return a trimmed version of the value of the template parameter with the specified `key`.
---Return `nil` if the parameter is empty or unset.
---@param key string|number
---@return string|nil
local function getArg(key)
local value = args_table[key]
if not value then
return nil
end
value = trim(value)
if value == '' then
return nil
end
return value
end
local p = {}
p.loop = function(frame)
args_table = frame:getParent().args
local ret = ''
ret = ret..(getArg('linksuffix') or '?')..(getArg('input') or 'Z')..(getArg('string') or '8')
mw.log(ret)
return spliton(getArg('input'))
end
return p