lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 01/16/2014 07:33 PM, Rena wrote:
The way I implemented LTN12 was that a source or filter can return nil
to signal the end of the data, or an empty string if no data is
available (e.g. for a non-blocking socket which hasn't yet received
another packet). I found that simplified the design of some parts. (e.g.
functions that expect a string often don't mind if that string is empty,
so they don't need to check for it.)

You're right, there is no reason the decoder must be prohibited from emitting a empty string mid-stream, even tough my decoder did not do such a thing. Signalling the end of a stream with a nil is a better idiom.

I modified the decoder accordingly, and as a side effect the decoding of a empty string is more consistent: the message "3:abc" emits "length 2, fragment 'abc', fragment nil", and the message "0:" emits "length 0, fragment '', fragment nil"

Thanks for the reminder,

Jorge