Difference between revisions of "Module:HonorTabs"

From Pathfinder Wiki
Line 19: Line 19:
  
 
function prepareAnswerVariants(variants)
 
function prepareAnswerVariants(variants)
t_variants = explode(";;", variants)
+
-- get the variants
 +
t_variants = explode(variants, ";;")
 
result_string = ""
 
result_string = ""
 
for key, value in pairs(t_variants) do
 
for key, value in pairs(t_variants) do
result_string = result_string .. " * " .. key .. " -- " .. value
+
result_string = result_string .. "* " .. key .. " -- " .. value .."\n"
 
end
 
end
return result_string
+
-- get the subvariants
end
+
for key, value in pairs(t_variants) do
 
+
value = explode(value, ";")
function splitString(inputstring, seperator)
+
end
sep=sep or '%s'
+
result_string2 = ""
local t={}
+
for key, value in pairs(t_variants) do
for str in string.gmatch(inputstring, "("..seperator..")") do
+
result_string2 = result_string2 .. "top level\n"
table.insert(t, str)
+
for key, val in pairs(value) do
 +
result_string2 = result_string2 .. "* " .. key .. " -- " .. val .."\n"
 +
end
 
end
 
end
return t
+
 +
return result_string2
 
end
 
end
  
-- explode(seperator, string)
+
function explode(str, seperator)
function explode(seperator,str)
 
 
   local t, ll
 
   local t, ll
 
   t={}
 
   t={}

Revision as of 21:28, 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)
	-- get the variants
	t_variants = explode(variants, ";;")
	result_string = ""
	for key, value in pairs(t_variants) do
		result_string = result_string .. "* " .. key .. " -- " .. value .."\n"
	end
	-- get the subvariants
	for key, value in pairs(t_variants) do
		value = explode(value, ";")
	end
	result_string2 = ""
	for key, value in pairs(t_variants) do
		result_string2 = result_string2 .. "top level\n"
		for key, val in pairs(value) do
			result_string2 = result_string2 .. "* " .. key .. " -- " .. val .."\n"
		end
	end
	
	return result_string2
end

function explode(str, seperator)
   local t, ll
   t={}
   ll=0
   if(#p == 1) then
      return {str}
   end
   while true do
      l = string.find(str, seperator, ll, true) -- find the next d in the string
      if l ~= nil then -- if "not not" found then..
         table.insert(t, string.sub(str,ll,l-1)) -- Save it in our array.
         ll = l + 1 -- save just after where we found it for searching next time.
      else
         table.insert(t, string.sub(str,ll)) -- Save what's left in our array.
         break -- Break at end, as it should be, according to the lua manual.
      end
   end
   return t
end

return p