[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua 5.2 and continue
- From: Tomas Guisasola Gorham <tomas@...>
- Date: Sun, 31 Jan 2010 22:45:12 -0200 (BRST)
What's the problem with this version?
while true do
-- Read 10 bytes of data.
-- Last 9 bytes of previous run are re-used first if needed.
data = socket:read(10, data:sub(2))
if not data then
-- Serious error, break the loop
-- Check packet start code
if data:byte(1) == 0x47 then -- inverted condition
-- Parse raw bytes into a table with keys
pkt = convert(data)
-- More packet validation checking
if verifyHeader(pkt) then -- inverted condition
-- We used all data of this packet, don't re-use any of it
-- in the next run
data = ""
-- Do something with the packet
if pkt.cmd == CMD_EXIT then
elseif pkt.cmd == CMD_FOO then
The code becomes more indented, but in this specific case, it is
not a problem to me. To me this version is clearer than yours, but I
am sure this is a matter of taste :-)