lua5.1循环错误结束预期(关闭'而')

时间:2014-03-22 22:57:12

标签: while-loop lua lua-5.1

无论我把“结束”放在哪里,它仍然会给我这个错误,

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

代码就在这里,

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
你可以告诉我或告诉我我做错了吗?

1 个答案:

答案 0 :(得分:1)

在您发布的代码中,只有一端。这个关闭你的if块,但不关闭你的while和功能块。 你需要另外两个目的。

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

这应该解决它。