Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- codeString = ""
- inputString = ""
- commands = {"<",">",".",",","[","]","+","-"}
- values = {}
- iterator = 1
- pointer = 1
- running = false
- input = false
- for i = 1, 30000 do
- values[i] = 0
- end
- function on.paint(gc)
- if running then
- executeCode(gc)
- else
- writeCode(gc)
- end
- timer.start(0.01)
- end
- function on.timer()
- timer.stop()
- refresh()
- end
- function on.charIn(ch)
- if running == false then
- for i,v in pairs (commands) do
- if ch == v then
- codeString = codeString .. ch
- refresh()
- end
- end
- end
- if input then
- values[pointer] = string.byte(ch)
- input = false
- end
- end
- function on.backspaceKey()
- if running == false then
- if string.len(codeString) > 0 then
- codeString = string.sub(codeString, 1, string.len(codeString) - 1)
- end
- end
- refresh()
- end
- function on.enterKey()
- if running then
- running = false
- elseif running == false then
- running = true
- end
- refresh()
- end
- function writeCode(gc)
- gc:drawString(codeString, 0, 0, "top")
- refresh()
- end
- function executeCode(gc)
- local str = string.sub(codeString, iterator, iterator)
- if str == "," then
- input = true
- end
- if str == "." then
- gc:drawString(string.char(values[pointer]),0,0,"top")
- end
- if str == "<" then
- pointer = pointer - 1
- if pointer <= 0 then
- pointer = 30000
- end
- end
- if str == ">" then
- pointer = pointer + 1
- if pointer > 30000 then
- pointer = 1
- end
- end
- if str == "+" then
- values[pointer] = values[pointer] + 1
- end
- if str == "-" then
- values[pointer] = values[pointer] - 1
- end
- if str == "[" then
- if values[pointer] == 0 then
- while str ~= "]" do
- iterator = iterator + 1
- str = string.sub(codeString, iterator, iterator)
- end
- end
- end
- if str == "]" then
- if values[pointer] ~= 0 then
- while str ~= "[" do
- iterator = iterator - 1
- str = string.sub(codeString, iterator, iterator)
- end
- end
- end
- if input == false then
- gc:drawString(str, 0,10,"top")
- gc:drawString(values[pointer],0,20,"top")
- iterator = iterator + 1
- str = string.sub(codeString, iterator, iterator)
- else
- gc:drawString("Input char", 0, 10, "top")
- end
- if iterator > string.len(codeString) then
- iterator = 0
- running = false
- end
- --refresh()
- end
- function refresh()
- platform.window:invalidate()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement