Module:Sandbox/ChaoticShadow/SongDataLine: Difference between revisions

From TestWiki
Content added Content deleted
No edit summary
No edit summary
Line 7: Line 7:
local what = ''
local what = ''


function string:split(delimiter)
function split(inputstr, sep)
local result = { }
if sep == nil then
local from = 1
sep = "%s"
end
local delim_from, delim_to = string.find( self, delimiter, from )
local t={}
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
from = delim_to + 1
table.insert(t, str)
end
delim_from, delim_to = string.find( self, delimiter, from )
return t
end
table.insert( result, string.sub( self, from ) )
return result
end
end



function p.main(frame)
function p.main(frame)
Line 25: Line 24:
for k,v in pairs(args) do
for k,v in pairs(args) do
what = what .. v
what = what .. v
local lines = tostring(v):split("\n")
local lines = split(v, "\n")
for _,line in ipairs(lines) do
for _,line in ipairs(lines) do
root:tag('li'):wikitext(line)
root:tag('li'):wikitext(line)

Revision as of 06:00, 25 June 2021

Documentation for this module may be created at Module:Sandbox/ChaoticShadow/SongDataLine/doc

local getArgs = require('Module:Arguments').getArgs

local p = {}
local args = {}

local root = mw.html.create('ul')
local what = ''

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


function p.main(frame)
	args = getArgs(frame)

	for k,v in pairs(args) do
		what = what .. v
		local lines = split(v, "\n")
		for _,line in ipairs(lines) do
			root:tag('li'):wikitext(line)
		end
	end
	
	return '<pre>' .. mw.dumpObject(args) .. '</pre>' 
	.. '<br>' .. 
	'<pre>' .. what .. '</pre>'
end

return p