Module:Explode String: Difference between revisions

From Valheim Wiki
Created page with "local p = {} p.loop = function(frame) local stage = frame.args.stage local rows = {} -- the actual looping part for value in mw.text.gsplit(stage, ',') do table.insert(r..."
 
No edit summary
Line 1: Line 1:
---A cached version of the current frame, the interface to the parser.
local currentFrame
---Holds the arguments from the template call.
local args_table
---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 = {}
local p = {}
p.loop = function(frame)
p.loop = function(frame)
Line 15: Line 36:
return {
return {


go = function(frame, args)
loop = function(frame, args)
string = getArg('string')
string = getArg('string')
linksuffix = getArg('linksuffix') or ''
linksuffix = getArg('linksuffix') or ''

Revision as of 21:04, 18 February 2021

Documentation for this module may be created at Module:Explode String/doc

---A cached version of the current frame, the interface to the parser.
local currentFrame
---Holds the arguments from the template call.
local args_table

---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)
	local stage = frame.args.stage
	local rows = {}
	-- the actual looping part
	for value in mw.text.gsplit(stage, ',') do
		table.insert(rows, '|' .. value)
	end
	
	return ' {|\n' .. table.concat(rows, '\n|-\n') .. '\n|}'
end

-----------------------------------------------------------------
-- main return object
return {

loop = function(frame, args)
	string = getArg('string')
	linksuffix = getArg('linksuffix') or ''

	-- output
	return string..linksuffix..'test'

end,

}