Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Project info:
- Name: Pig
- Creator: Jesusthekiller
- Language: Lua (CC)
- Website: None
- License: GNU GPL
- License file can be fount at www.jesusthekiller.com/license-gpl.html
- Version: 1.2
- ]]--
- --[[
- Changelog:
- 1.0:
- Public Release
- 1.1:
- Now proper Pig Latin :P
- way prefix support
- 1.2:
- File output
- ]]--
- --[[
- LICENSE:
- Pig - Pig Latin translator
- Copyright (c) 2013 Jesusthekiller
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
- ]]--
- local args = {...}
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- if #args < 2 then
- print([[
- Usage:
- Code:
- pig c <text>
- Decode:
- pig d <text>
- Output is also saved to pig_out]])
- return
- end
- local function isVowel(l)
- l = l:lower()
- local cosonant = {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'x', 'z', 'w', 'y'}
- for i = 1, #cosonant do
- if l == cosonant[i] then
- return false
- end
- end
- return true
- end
- local f = fs.open("pig_out", "w")
- local ow = write
- local write = function(t)
- f.write(t)
- f.flush()
- ow(t)
- end
- if args[1] == "c" then
- for i = 2, #args do
- local w = args[i]
- if isVowel(w:sub(1,1)) then
- if #w < 2 then
- write(w.."way ")
- else
- write(w:sub(2)..w:sub(1,1).."way ")
- end
- else
- if #w < 2 then
- write(w.."ay ")
- else
- write(w:sub(2)..w:sub(1,1).."ay ")
- end
- end
- end
- elseif args[1] == "d" then
- for i = 2, #args do
- local w = args[i]
- if w:sub(#w-2) == "way" then
- if #w == 4 then
- write(w:sub(1,1).." ")
- else
- write(w:sub(#w-3, #w-3)..w:sub(1, #w-4).." ")
- end
- else
- if #w == 3 then
- write(w:sub(1,1).." ")
- else
- write(w:sub(#w-2, #w-2)..w:sub(1, #w-3).." ")
- end
- end
- end
- else
- print([[
- Usage:
- Code:
- pig c <text>
- Decode:
- pig d <text>]])
- return
- end
- local x, y = term.getCursorPos()
- term.setCursorPos(1, y + 1)
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement