Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sub, char, byte, match = string.sub, string.char, string.byte, string.match
- local cpu = {}
- local params = _ARGS
- if not params then return end
- local ret = ''
- local text, chars = match(AnsiToUtf8(params), '(%S+)%s*(.*)')
- local l, j, brc, i = 0, 0, 0, 0
- local function getChar()
- l = l + 1
- return byte(chars, l)
- end
- while #text > i do
- i = i + 1
- local ch = sub(text, i, i)
- if ch == '>' then j = j + 1
- elseif ch == '<' then j = j - 1
- elseif ch == '+' then cpu[j] = ( cpu[j] or 0 ) + 1
- elseif ch == '-' then cpu[j] = ( cpu[j] or 0 ) - 1
- elseif ch == '.' then ret = ret .. char(cpu[j])
- elseif ch == ',' then cpu[j] = getChar()
- elseif ch == '[' then
- if not cpu[j] or cpu[j] == 0 then
- brc = brc + 1
- while brc ~= 0 do
- i = i + 1
- local chh = sub(text, i, i)
- if chh == '[' then brc = brc + 1
- elseif chh == ']' then brc = brc - 1 end
- end
- end
- elseif ch == ']' then
- if cpu[j] and cpu[j] > 0 then
- brc = brc + 1
- while brc ~= 0 do
- i = i - 1
- local chh = sub(text, i, i)
- if chh == '[' then brc = brc - 1
- elseif chh == ']' then brc = brc + 1 end
- end
- i = i - 1
- end
- end
- end
- return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement