lua-users home
lua-l archive

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


Op Ma., 3 Sep. 2018 om 13:41 het actboy168 <actboy168@gmail.com> geskryf:
>
> In struct  library , option `s` means read a zero-terminated string.So the same test is
> local struct = require 'struct'
> print(struct .unpack('s', 'ABC'))

Exactly. If you want the error message, use 's', not 'z'.

> string.unpack('s', 'ABC')
stdin:1: bad argument #2 to 'unpack' (data string too short)
stack traceback:
    [C]: in function 'string.unpack'
    stdin:1: in main chunk
    [C]: in ?



> Dirk Laurie <dirk.laurie@gmail.com> 于2018年9月3日周一 下午6:23写道:
>>
>> Op Ma., 3 Sep. 2018 om 12:08 het actboy168 <actboy168@gmail.com> geskryf:
>> >
>> > But the struct library will raise an error.
>>
>> True, but that error is:
>>    bad argument #1 to 'unpack' (invalid format option 'z')
>> I.e. the option 'z' is an addition available in the Lua 5.3 library version.
>>
>
>
> -- actboy168