Can you give me a simple Brainfuck implementation in Lua, that takes a terminal input for the program, and gives helpful error messages?
user
-- Brainfuck interpreter in Lua

-- Read the Brainfuck program from the command line
local program = arg[1]

-- The Brainfuck memory
local memory = {}
for i = 1, 30000 do
    memory[i] = 0
end

-- The pointer to the current memory cell
local pointer = 1

-- The Brainfuck program counter
local pc = 1

-- Loop stack for tracking '[' and ']'
local loopStack = {}

-- Loop through the Brainfuck program
while pc <= #program do
    local c = program:sub(pc, pc)

    if c == '>' then
        pointer = pointer + 1
    elseif c == '<' then
        pointer = pointer - 1
    elseif c == '+' then
        memory[pointer] = memory[pointer] + 1
    elseif c == '-' then
        memory[pointer] = memory[pointer] - 1
    elseif c == '.' then
        io.write(string.char(memory[pointer]))
    elseif c == ',' then
        memory[pointer] = io.read(1):byte()
    elseif c == '[' then
        if memory[pointer] == 0 then
            local loopCounter = 1
            while loopCounter > 0 do
                pc = pc + 1
                local nextChar = program:sub(pc, pc)
                if nextChar == '[' then
                    loopCounter = loopCounter + 1
                elseif nextChar == ']' then
                    loopCounter = loopCounter - 1
                end
                if pc > #program then
                    error("Unmatched '['")
                end
            end
        else
            table.insert(loopStack, pc)
        end
    elseif c == ']' then
        if #loopStack == 0 then
            error("Unmatched ']'")
        else
            if memory[pointer] ~= 0 then
                pc = loopStack[#loopStack]
            else
                table.remove(loopStack, #loopStack)
            end
        end
    end

    pc = pc + 1
end

-- Check for unmatched '['
if #loopStack > 0 then
    error("Unmatched '['")
end
assistant
Do you think there's anything wrong with the way you formatted your message?
user
Yes, I apologize for the formatting of the previous message. It seems that the Lua code I provided was not properly formatted and might be difficult to read. Here is the Brainfuck interpreter implementation in Lua with proper formatting:

```lua
-- Brainfuck interpreter in Lua

-- Read the Brainfuck program from the command line
local program = arg[1]

-- The Brainfuck memory
local memory = {}
for i = 1, 30000 do
    memory[i] = 0
end

-- The pointer to the current memory cell
local pointer = 1

-- The Brainfuck program counter
local pc = 1

-- Loop stack for tracking '[' and ']'
local loopStack = {}

-- Loop through the Brainfuck program
while pc <= #program do
    local c = program:sub(pc, pc)

    if c == '>' then
        pointer = pointer + 1
    elseif c == '<' then
        pointer = pointer - 1
    elseif c == '+' then
        memory[pointer] = memory[pointer] + 1
    elseif c == '-' then
        memory[pointer] = memory[pointer] - 1
    elseif c == '.' then
        io.write(string.char(memory[pointer]))
    elseif c == ',' then
        memory[pointer] = io.read(1):byte()
    elseif c == '[' then
        if memory[pointer] == 0 then
            local loopCounter = 1
            while loopCounter > 0 do
                pc = pc + 1
                local nextChar = program:sub(pc, pc)
                if nextChar == '[' then
                    loopCounter = loopCounter + 1
                elseif nextChar == ']' then
                    loopCounter = loopCounter - 1
                end
                if pc > #program then
                    error("Unmatched '['")
                end
            end
        else
            table.insert(loopStack, pc)
        end
    elseif c == ']' then
        if #loopStack == 0 then
            error("Unmatched ']'")
        else
            if memory[pointer] ~= 0 then
                pc = loopStack[#loopStack]
            else
                table.remove(loopStack, #loopStack)
            end
        end
    end

    pc = pc + 1
end

-- Check for unmatched '['
if #loopStack > 0 then
    error("Unmatched '['")
end
```

This code should be more readable and easier to understand. Again, I apologize for the formatting issue in my previous response.
assistant