Module:OnshokoeseScript: Difference between revisions

From Constructed Worlds Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local p = {}
local p = {}
local CharData = mw.loadData( 'Module:OnshokoeseScript/data' )
function p._onshokoese( humanwords, size )
    local output_string = {}
    local humanwords = string.lower(humanwords)
    local span = mw.html.create( 'span' )
    if (size == nil or size == '') then size='14' end
    local i=1
    local j=string.len(humanwords)
    while (i <= j) do
        local replacement = CharData[humanwords:sub(i,i + 2)]
        if replacement ~= nil then
            table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
            i = i + 3
        else
            local replacement = CharData[humanwords:sub(i,i + 1)]
        if replacement ~= nil then
            table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
            i = i + 2
        else
            local replacement = CharData[humanwords:sub(i,i)]
        if replacement ~= nil then
            table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
            i = i + 1
        else
            table.insert(output_string,'&nbsp;&nbsp;')
            i = i + 1
        end
        end
        end
    end
    span    :css( 'font-size', size..'px' )
            :wikitext( table.concat(output_string) )
    return tostring(span)
end


function p.main(frame)
function p.main(frame)
local args = getArgs(frame)
    local string_input = frame.args[1]
return p._main(args)
    local num_input = frame.args[2]
    return p._onshokoese(string_input, num_input)
 
end
end



Latest revision as of 22:59, 25 April 2024

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

local getArgs = require('Module:Arguments').getArgs
local p = {}

local CharData = mw.loadData( 'Module:OnshokoeseScript/data' )

function p._onshokoese( humanwords, size )
    local output_string = {}
    local humanwords = string.lower(humanwords)
    local span = mw.html.create( 'span' )
    if (size == nil or size == '') then size='14' end
    local i=1
    local j=string.len(humanwords)
    while (i <= j) do
        local replacement = CharData[humanwords:sub(i,i + 2)]
        if replacement ~= nil then
            table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
            i = i + 3
        else
            local replacement = CharData[humanwords:sub(i,i + 1)]
        if replacement ~= nil then
            table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
            i = i + 2
        else
            local replacement = CharData[humanwords:sub(i,i)]
        if replacement ~= nil then
            table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
            i = i + 1
        else
            table.insert(output_string,'&nbsp;&nbsp;')
            i = i + 1
        end
        end
        end
    end
    span    :css( 'font-size', size..'px' )
            :wikitext( table.concat(output_string) )
    return tostring(span)
end

function p.main(frame)
    local string_input = frame.args[1]
    local num_input = frame.args[2]
    return p._onshokoese(string_input, num_input)
   
end

function p._main(args)
	local first = args[1] or ''
	local second = args[2] or ''
	return first .. ' ' .. second
end

return p