lua-users home
lua-l archive

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


> 1) why is in string.pack the default length for c (simple string) 1,
> and not the string's length?

Coding a variable-length string without its length would be
unreadable (there would be no way to unpack it). (In particular,
we want that anything packed with some format 'f' should be readable
with exactly the same format.)


> pack() throws an error if the string's length does not match the
> coded length, but there is no method to encode the length as a
> variable

Don't you mean option "s"?


> 2) why is there no way to put literal characters into the pack()ed string?

Binary data usually do not contain fixed stuff. (Even the name 'pack'
implies not wasting space...). You can always code literal characters
with a combination of "c" and literal strings.

-- Roberto