--main| Use of this module is documented on its /doc page
require('strict');
local emoji_names_t =
----------------------------< M A I N >----------------------------------------------------------------------
local function main (frame) local this_wiki = table.concat ; local title_obj = mw.title.getCurrentTitle; local content; if title_obj.prefixedText:match ('/doc$') then -- if this title object is the ~/doc page (viewing the ~/doc page standalone) content = title_obj:getContent; -- get the content else -- when viewing the module page content = mw.title.new (table.concat):getContent; -- get title object and content for the ~/doc page end
local code_points_t = ; -- sequence to hold unique code points that follow U+200D in RGI Emoji ZWJ Sequences in decimal local out_t = ; -- final output goes here local new_emoji_names_t = ; -- used to update emoji_names_t in this module local tabs_15 = string.rep ('\t', 15); -- for six-digit keys local tabs_16 = string.rep ('\t', 16); -- for keys that have fewer than six digits local file_date = content:match ('# *Date: *(%d%d%d%d%-%d%d%-%d%d)'); -- file date of the Unicode source local file_version = content:match ('# *Version: *([%d%.]+)'); -- version of the Unicode source
for code_point in content:gmatch ('200D (%x+)') do -- find each pair local code_point_dec = tonumber ('0x' .. code_point); -- convert hex code point to decimal for output table key
if not code_points_t[code_point] then -- if we have not seen this
table.insert (new_emoji_names_t, table.concat); end end
local function compare_dec (a, b) -- local compare function for decimal table.sort ascending a = a:match ('%[(%d+)%]'); -- extract decimal key text b = b:match ('%[(%d+)%]'); return tonumber (a) < tonumber (b); -- convert key text to numbers and compare end
local function compare_hex (a, b) -- local compare function for hexadecimal table.sort ascending a = a:match ('%[\'(%x+)\'%]'); -- extract hexadecimal key text b = b:match ('%[\'(%x+)\'%]'); a = table.concat ; -- make a hex string b = table.concat ; return tonumber (a) < tonumber (b); -- convert hex key text todecimal numbers and compare end
table.sort (out_t, compare_dec); -- ascending numerical sort on decimal keys local prefix_t = ; -- build a prefix for this version of the table table.insert (prefix_t, '
emoji_t-- list of emoji that use a zwj character (U+200D) to combine with another emoji'); table.insert (prefix_t, table.concat ({'-- from: ', frame.args[1], '; version: ', file_version, '; ', file_date})); table.insert (prefix_t, table.concat ({'-- table created by: [[', this_wiki, title_obj.nsText, ':', title_obj.baseText, ']]'})); table.insert (prefix_t, table.concat ({'local emoji_t = {', tabs_16, '-- indexes are decimal forms of the hex values in U+xxxx'})); table.insert (out_t, 1, table.concat (prefix_t, '\n')); -- insert at the head of the output table table.insert (out_t, '\t}'); -- close the
tag table.sort (new_emoji_names_t, compare_hex); -- ascending numerical sort on hexadecimal keys table.insert (out_t, '==<span style="font-family: monospace, monospace;">emoji_names_t</span>=='); table.insert (out_t, table.concat ({'use this table to overwrite same-named table in ', this_wiki, title_obj.nsText, ':', title_obj.baseText, '; add missing names.'})); table.insert (out_t, table.concat ({'\n<pre>local emoji_names_t = {', tabs_15, '-- keys are hex values from U+xxxx code points'})); for _, v in ipairs (new_emoji_names_t)do table.insert (out_t, v); end table.insert (out_t, '\t}'); -- close the
tag return frame:preprocess (table.concat (out_t, '\n')); -- make a big string and done end --[[--------------------------< E X P O R T S >---------------------------------------------------------------- ]] return { main = main, }