Difference between revisions of "Module:Emoji"

From blackwiki
Jump to navigation Jump to search
blackwiki>Trappist the monk
blackwiki>Izno
(make defaults obvious)
Line 6: Line 6:
 
local emoname = frame.args[1] and mw.text.trim(frame.args[1])
 
local emoname = frame.args[1] and mw.text.trim(frame.args[1])
 
if '' == emoname then
 
if '' == emoname then
emoname = 'smiley';
+
local name_default = 'smiley'
 +
emoname = name_default;
 
end
 
end
 
return emotbl[emoname] or emoname
 
return emotbl[emoname] or emoname
Line 15: Line 16:
 
local emocode = frame.args[1] and mw.text.trim(frame.args[1])
 
local emocode = frame.args[1] and mw.text.trim(frame.args[1])
 
if '' == emocode then
 
if '' == emocode then
emocode = '1f603';
+
local code_default = '1f603'
 +
emocode = code_default;
 
end
 
end
 
return emorevtbl[emocode] or emocode
 
return emorevtbl[emocode] or emocode

Revision as of 14:05, 25 March 2019

Module:Emoji implements two functions:

emocode 
It takes one unnamed parameter, the name of the emoji, and returns the hex code for the corresponding emoji. If no name is supplied it uses "smiley" as the default (and returns 1f603).
emoname 
It takes one unnamed parameter, the hex code of the emoji, and returns the name for the corresponding emoji. If no name is supplied it uses "1f603" as the default (and returns smiley).

It stores the mapping from name to code in Module:Emoji/data, which internally generates the reverse lookup table from code to name.

Examples

  • {{#invoke:Emoji | emocode | wink}}1f609
  • {{#invoke:Emoji | emocode | grin}}1f601
  • {{#invoke:Emoji | emocode | 8ball}}1f3b1
  • {{#invoke:Emoji | emocode }}
  • {{#invoke:Emoji | emoname | 1f62b}}tired_face
  • {{#invoke:Emoji | emoname }}



local p= {}
local emodata = mw.loadData ('Module:Emoji/data')

function p.emocode(frame)
	local emotbl = emodata.emotbl
	local emoname = frame.args[1] and mw.text.trim(frame.args[1])
	if '' == emoname then
		local name_default = 'smiley'
		emoname = name_default;
	end
	return emotbl[emoname] or emoname
end

function p.emoname(frame)
	local emorevtbl = emodata.emorevtbl
	local emocode = frame.args[1] and mw.text.trim(frame.args[1])
	if '' == emocode then
		local code_default = '1f603'
		emocode = code_default;
	end
	return emorevtbl[emocode] or emocode
end

return p