-- Module:ASCII code -- wjk -- User:Matroc-- Minimal error checking - using Lua built in functions string.byte and string.char-- could possibly change to mw.ustring.codepoint and mw.ustring.char for UTF-8-- dealing with strings/numbers different for each of the above-- using 32 or word "space" for return-- essentially both functions for basic ASCII - 32 - 126 and not extended at this time-- Just a basic test can be modified accordingly
-- Function to get number code for ASCII character is called asciicode-- For invoke: -- Function to get character from number code-- ie.
-- FUNCTION ASCIICODE
local p =
function p.asciicode(frame) local char = "" if frame.args[1] ~= nil and frame.args[1] ~= "" then -- checking and create a default char = string.sub(frame.args[1], 1, 1) -- insure only 1 character or make default of space else char = " " end if char:byte >= 32 and char:byte <= 126 then -- check if between 32 and 126 if char:byte
-- FUNCTION CODEASCII
function p.codeascii(frame) local num = "0" if frame.args[1] ~= nil and frame.args[1] ~= "" then num = frame.args[1] or "32" else num = "0" end num = tonumber(num) -- convert string to be a number if num
32 then return "space" -- if 32 return word space else return tostring(num):char end else return "space" -- otherwise we will return the word space endend
return p