lua-users home
lua-l archive

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


Здравствуйте, Roberto.

Вы писали 29 ноября 2014 г., 16:51:48:

>> > Can't you use #string.pack(fmt, ...), with specific dummy arguments?
>>
>> 0 works everywhere except c[n], which needs the exact length to match.
>>
>> But "hard to implement in Lua" is fair also for the dummy argument
>> approach. You need to be able to generate a list `0,0,0,0,...` of at least
>> the right length, punctuated by the occasional string.rep(' ',n). This
>> amounts to parsing `fmt` in Lua.

> I was not proposing a "generic" implementation for pack size, just a
> simple way to compute the size of a supposely known format. (Anyway,
> even the offical size function from the struct library does not work for
> all formats...)

> -- Roberto


 I think about basic read function.
  function fmtread(stream, fmt)
    local size = struct.size(fmt)
    local data = stream.read(size)
    return struct.unpack(fmt, data)
  end

Create new dummy string each time is not good idea and also how I can determine dummy arguments?

Of course size has no meaning to VLA/VLS.



---
Это сообщение свободно от вирусов и вредоносного ПО благодаря защите от вирусов avast!
http://www.avast.com