zhivotnoya

cPrint.lua

Oct 16th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. function sc(x, y)
  2.     term.setCursorPos(x, y)
  3. end
  4. function clear(move)
  5.     term.clear()
  6.     if move ~= false then sc(1,1) end
  7. end
  8. function sb(color)
  9.     term.setBackgroundColor(color)
  10. end
  11. function st(color)
  12.     term.setTextColor(color)
  13. end
  14. function cCode(code)
  15.     return 2 ^ tonumber(h, 16)
  16. end
  17. function toCode(n)
  18.     return string.format('%x', n)
  19. end
  20. function cprint(text)
  21.     local i = 0
  22.         while true  do
  23.     i = i + 1
  24.     if i > #text then break end
  25.         local c = text:sub(i, i)
  26.         if c == "\\" then
  27.             if text:sub(i+1, i+1) == "&" then
  28.                 write("&")
  29.                 i = i + 1
  30.             elseif text:sub(i+1, i+1) == "$" then
  31.                 write("$")
  32.                 i = i + 1
  33.             else
  34.                 write(c)
  35.             end
  36.         elseif c == "&" then
  37.             st(cCode(text:sub(i+1, i+1)))
  38.             i = i + 1
  39.         elseif c == "$" then
  40.             sb(cCode(text:sub(i+1, i+1)))
  41.             i = i + 1
  42.         else
  43.             write(c)
  44.         end
  45.     end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment