Skip to content

Instantly share code, notes, and snippets.

@tiansh
Created January 25, 2016 04:29
Show Gist options
  • Save tiansh/ddb7fce994cce3428b69 to your computer and use it in GitHub Desktop.
Save tiansh/ddb7fce994cce3428b69 to your computer and use it in GitHub Desktop.

Revisions

  1. tiansh created this gist Jan 25, 2016.
    73 changes: 73 additions & 0 deletions mo.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    function Morse(ori)

    MorseMapping = {
    ["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"] = "−−..",
    ["0"] = "−−−−−",
    ["1"] = ".−−−−",
    ["2"] = "..−−−",
    ["3"] = "...−−",
    ["4"] = "....−",
    ["5"] = ".....",
    ["6"] = "−....",
    ["7"] = "−−...",
    ["8"] = "−−−..",
    ["9"] = "−−−−.",
    ["."] = ".−.−.−",
    [","] = "−−..−−",
    ["?"] = "..−−..",
    ["'"] = ".−−−−.",
    ["!"] = "−.−.−−",
    ["/"] = "−..−.",
    ["("] = "−.−−.",
    [")"] = "−.−−.−",
    ["&"] = ".−...",
    [":"] = "−−−...",
    [";"] = "−.−.−.",
    ["="] = "−...−",
    ["+"] = ".−.−.",
    ["-"] = "−....−",
    ["_"] = "..−−.−",
    ["\""] = ".−..−.",
    ["$"] = "...−..−",
    ["@"] = ".−−.−.",
    ["_"] = "/"
    }

    if #ori == 0 then return end
    local result = ""
    ori = string.lower(ori)
    for c in ori:gmatch"." do
    result = result .. MorseMapping[c] .. " "
    end
    result = result .. "/ "
    return {result, string.sub(result, 0, string.len(result) - 3)}

    end

    ime.register_command("mo", "Morse", "摩尔斯电码", "none")