lua-users home
lua-l archive

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

> On 7 April 2016 at 13:34, Duane Leslie <> wrote:
>> LUA_PACKPADBYTE (not necessarily '\0')
>> The padding option is definitely convenient but I dislike padding with LUA_PACKPADBYTE rather than '\0'
> LUA_PACKPADBYTE *is* defined as '\0'.
> If you're defining it to something else, don't complain that it's different....

My issue is not so much what it may or may not be defined as, but
rather that semantically it is not the same as '\0' and this has the
flow on effect that when it is silently inserted by `pack()` it is
then loudly returned by `unpack()`.

In all other cases `unpack()` swallows any LUA_PACKPADBYTE but it
cannot in the case of the fixed string format because it allows any
data to be inserted and so cannot differentiate padding bytes from
legitimate data.  If you pad the zero terminated string with '\0' then
you can remove them when unpacking because the semantics are clear.