Dr01d3k4Join Date: 2007-10-11 Post Count: 17916 |
kingimpy is right, just some things went a little bit wrong. This is what I use:
convert = {
a = ".-",
b = "-...",
c = "-.-.",
d = "-..",
e = ".",
f = "..-.",
g = "--.",
h = "....",
i = "..",
j = ".---",
k = "-.-",
l = "._..",
m = "--",
n = "-.",
o = "---",
p = ".--.",
q = "--.-",
r = ".-.",
s = "...",
t = "-",
u = "..-",
v = "...-",
w = ".--",
x = "-..-",
y = "-.--",
z = "--.."
}
numbers = {
{1, ".----"},
{2, "..---"},
{3, "...--"},
{4, "....-"},
{5, "....."},
{6, "-...."},
{7, "--..."},
{8, "---..."},
{9, "----."},
{0, "-----"}
}
function _G.tomorse(str)
local sstr = tostring(str)
if (sstr == nil) then return str end
local a = ""
for b = 1, #str do
local d = string.lower(string.sub(str, b, b))
if (d == " ") then
a = a.."/ "
elseif (tonumber(d) ~= nil) then
for c = 1, #numbers do
if (numbers[c][1] == tonumber(d)) then
a = a..""..numbers[c][2].." "
end
end
else
for i, v in pairs(convert) do
if (d == i) then
a = a..""..v.. " "
end
end
end
end
return a
end
function _G.tostr(m)
local sm = tostring(m)
if (sm == nil) then return m end
local am = string.gsub(sm, " ", "|")
local tbl = { }
local curstr = ""
local str = ""
for a = 1, #am do
if (string.sub(am, a, a) ~= "|") then
curstr = curstr..""..string.sub(am, a, a)
else
table.insert(tbl, curstr)
curstr = ""
end
end
for b = 1, #tbl do
for c = 1, #numbers do
if (tbl[b] == numbers[c][2]) then
str = str..""..numbers[c][1].. ""
end
end
for i, v in pairs(convert) do
if (tbl[b] == v) then
str = str..""..tostring(i)
end
end
if (tbl[b] == "/") then
str = str.." "
end
end
return str
end |