user3103366
user3103366

Reputation: 65

lua5.1 loop error end expected (to close 'while' )

no matter where I put the "end" it still gives me this error,

lua: ch.lua:157: 'end' expected (to close 'while' at line 138) near '<eof>'>Exit code: 1

the code is here,

function ch_handler()
stopped = false
while not err or stopped do
    res, err = self.sock.sock_connection:receive()
    if not (res == nil) then
        self.getEvent({res})
    else
        error('CONNECTION DEAD: ' .. err, 2) -- return an error message
        self.sock[room.name]:close() -- should close the dead connection
        event.onDisconnect(room.name)
        stopped = true
        break 
    end

can you tell me or show me what I'm doing wrong?

Upvotes: 1

Views: 211

Answers (1)

pedro-b
pedro-b

Reputation: 11

On the code you posted,there is only one end. This one closes your if block, but not your while and function block. You need two more ends there.

function ch_handler()
    stopped = false
    while not err or stopped do
        res, err = self.sock.sock_connection:receive()
        if not (res == nil) then
            self.getEvent({res})
        else
            error('CONNECTION DEAD: ' .. err, 2) -- return an error message
            self.sock[room.name]:close() -- should close the dead connection
            event.onDisconnect(room.name)
            stopped = true
            break 
        end
    end
end

This should fix it.

Upvotes: 1

Related Questions