Difference between revisions of "Module:HonorTabs"

From Pathfinder Wiki
Line 11: Line 11:
 
function p.createAnswerTab( frame )
 
function p.createAnswerTab( frame )
 
if frame.args.answerVariants then
 
if frame.args.answerVariants then
 
 
return "There are answer variants: " .. prepareAnswerVariants(frame.args.answerVariants)
 
return "There are answer variants: " .. prepareAnswerVariants(frame.args.answerVariants)
 
else
 
else
Line 20: Line 19:
  
 
function prepareAnswerVariants(variants)
 
function prepareAnswerVariants(variants)
t_variants = split(variants, ";;")
+
t_variants = splitString(variants, ";;")
 
result_string = ""
 
result_string = ""
 
for key, value in pairs(t_variants) do
 
for key, value in pairs(t_variants) do
Line 29: Line 28:
  
 
function splitString(inputstring, seperator)
 
function splitString(inputstring, seperator)
if seperator == nil then
+
sep=sep or '%s'
seperator = "%s"
 
end
 
 
local t={}
 
local t={}
for str in string.gmatch(inputstring, "^"..seperator) do
+
for str in string.gmatch(inputstring, "("..seperator..")") do
 
table.insert(t, str)
 
table.insert(t, str)
 
end
 
end
Line 40: Line 37:
  
 
function split(inputstr, sep)
 
function split(inputstr, sep)
sep=sep or '%s'
+
 
local t={}
 
local t={}
 
for field,s in string.gmatch(inputstr, "([^"..sep.."]*)("..sep.."?)") do
 
for field,s in string.gmatch(inputstr, "([^"..sep.."]*)("..sep.."?)") do

Revision as of 21:03, 27 April 2021

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

local p = {}

function p.hello( frame )
	return "Hello, world!"
end

function p.getLangSuffix( frame )
	return frame:expandTemplate{ title = 'GetLangSuffix' }
end

function p.createAnswerTab( frame )
	if frame.args.answerVariants then
		return "There are answer variants: " .. prepareAnswerVariants(frame.args.answerVariants)
	else
		return "There aren't any answer variants!"
	end
	
end

function prepareAnswerVariants(variants)
	t_variants = splitString(variants, ";;")
	result_string = ""
	for key, value in pairs(t_variants) do
		result_string = result_string .. " * " .. key .. " -- " .. value
	end
	return result_string
end

function splitString(inputstring, seperator)
	sep=sep or '%s'
	local t={}
	for str in string.gmatch(inputstring, "("..seperator..")") do
		table.insert(t, str)
	end
	return t
end

function split(inputstr, sep)
	
	local t={}
	for field,s in string.gmatch(inputstr, "([^"..sep.."]*)("..sep.."?)") do
		table.insert(t,field)  
		if s=="" then
			return t 
		end 
	end 
end


return p