Advertisement
s1ay3r44

Luaf*ck

Sep 29th, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. codeString = ""
  2. inputString = ""
  3. commands = {"<",">",".",",","[","]","+","-"}
  4. values = {}
  5. iterator = 1
  6. pointer = 1
  7. running = false
  8. input = false
  9.  
  10. for i = 1, 30000 do
  11.     values[i] = 0
  12. end
  13.  
  14.  
  15. function on.paint(gc)
  16.     if running then
  17.         executeCode(gc)
  18.     else
  19.         writeCode(gc)
  20.     end
  21.     timer.start(0.01)
  22. end
  23.  
  24. function on.timer()
  25.     timer.stop()
  26.     refresh()
  27. end
  28.  
  29. function on.charIn(ch)
  30.     if running == false then
  31.         for i,v in pairs (commands) do
  32.             if ch == v then
  33.                 codeString = codeString .. ch
  34.                 refresh()
  35.             end
  36.         end
  37.     end
  38.     if input then
  39.         values[pointer] = string.byte(ch)
  40.         input = false
  41.     end
  42. end
  43.  
  44. function on.backspaceKey()
  45.     if running == false then
  46.         if string.len(codeString) > 0 then
  47.             codeString = string.sub(codeString, 1, string.len(codeString) - 1)
  48.         end
  49.     end
  50.     refresh()
  51. end
  52.  
  53. function on.enterKey()
  54.     if running then
  55.         running = false
  56.     elseif running == false then
  57.         running = true
  58.     end
  59.    
  60.     refresh()
  61. end
  62.  
  63. function writeCode(gc)
  64.     gc:drawString(codeString, 0, 0, "top")
  65.     refresh()
  66. end
  67.  
  68. function executeCode(gc)
  69.     local str = string.sub(codeString, iterator, iterator)
  70.     if str == "," then
  71.         input = true
  72.     end
  73.     if str == "." then
  74.         gc:drawString(string.char(values[pointer]),0,0,"top")
  75.     end
  76.     if str == "<" then
  77.         pointer = pointer - 1
  78.         if pointer <= 0 then
  79.             pointer = 30000
  80.         end
  81.     end
  82.     if str == ">" then
  83.         pointer = pointer + 1
  84.         if pointer > 30000 then
  85.             pointer = 1
  86.         end
  87.     end
  88.     if str == "+" then
  89.         values[pointer] = values[pointer] + 1
  90.     end
  91.     if str == "-" then
  92.         values[pointer] = values[pointer] - 1
  93.     end
  94.     if str == "[" then
  95.         if values[pointer] == 0 then
  96.             while str ~= "]" do
  97.                 iterator = iterator + 1
  98.                 str = string.sub(codeString, iterator, iterator)
  99.             end
  100.         end
  101.     end
  102.     if str == "]" then
  103.         if values[pointer] ~= 0 then
  104.             while str ~= "[" do
  105.                 iterator = iterator - 1
  106.                 str = string.sub(codeString, iterator, iterator)
  107.             end
  108.         end
  109.     end
  110.     if input == false then
  111.         gc:drawString(str, 0,10,"top")
  112.         gc:drawString(values[pointer],0,20,"top")
  113.         iterator = iterator + 1
  114.         str = string.sub(codeString, iterator, iterator)
  115.     else
  116.         gc:drawString("Input char", 0, 10, "top")
  117.     end
  118.     if iterator > string.len(codeString) then
  119.         iterator = 0
  120.         running = false
  121.     end
  122.     --refresh()
  123. end
  124.  
  125. function refresh()
  126.     platform.window:invalidate()
  127. end
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement