Module:Sandbox/Erutuon/scripts

local p = {}

local cp_to_sc = require 'Module:Language/scripts'.codepointToScript

local function in_array(arr, val) for i, v in ipairs(arr) do		if v == val then return true end end return false end

local function mapIter(func, iter, iterable, initVal) local array = {} local i = 0 for x, y in iter, iterable, initVal do		i = i + 1 array[i] = func(y, x, iterable) end return array end

function p.list_chars_in_script(str) local scripts = {} for codepoint in mw.ustring.gcodepoint(str) do		local script = cp_to_sc(codepoint) scripts[script] = scripts[script] or {} local char = mw.ustring.char(codepoint) if not in_array(scripts[script], char) then table.insert(scripts[script], char) end end for script, characters in pairs(scripts) do		table.sort(characters) end return table.concat(		mapIter( function (codepoints, script) return ('\n* %s: %s') :format(script, table.concat(codepoints)) end, pairs(scripts))) end

function p.main(frame) return p.list_chars_in_script(frame.args[1]) end

return p