Difference between revisions of "Module:Emoji"
Jump to navigation
Jump to search
blackwiki>RexxS (we can simplify this if the data is loaded externally) |
blackwiki>Izno (make it clear these are defaults--could ostensibly add them to the data module) |
||
| Line 4: | Line 4: | ||
function p.emocode(frame) | function p.emocode(frame) | ||
local emotbl = emodata.emotbl | local emotbl = emodata.emotbl | ||
| − | local emoname = mw.text.trim(frame.args[1] or | + | local default_name = "smiley" |
| + | local emoname = mw.text.trim(frame.args[1] or default_code) | ||
return emotbl[emoname] or emoname | return emotbl[emoname] or emoname | ||
end | end | ||
| Line 10: | Line 11: | ||
function p.emoname(frame) | function p.emoname(frame) | ||
local emorevtbl = emodata.emorevtbl | local emorevtbl = emodata.emorevtbl | ||
| − | local emocode = mw.text.trim(frame.args[1] or | + | local default_name = "1f603" |
| + | local emocode = mw.text.trim(frame.args[1] or default_name) | ||
return emorevtbl[emocode] or emocode | return emorevtbl[emocode] or emocode | ||
end | end | ||
return p | return p | ||
Revision as of 12:00, 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 }}→Lua error: bad argument #1 to 'gsub' (string expected, got nil).{{#invoke:Emoji | emoname | 1f62b}}→tired_face{{#invoke:Emoji | emoname }}→smiley
local p= {}
local emodata = mw.loadData ('Module:Emoji/data')
function p.emocode(frame)
local emotbl = emodata.emotbl
local default_name = "smiley"
local emoname = mw.text.trim(frame.args[1] or default_code)
return emotbl[emoname] or emoname
end
function p.emoname(frame)
local emorevtbl = emodata.emorevtbl
local default_name = "1f603"
local emocode = mw.text.trim(frame.args[1] or default_name)
return emorevtbl[emocode] or emocode
end
return p