lua-users home
lua-l archive

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


2016-07-17 9:31 GMT+02:00 Sean Conner <sean@conman.org>:
> It was thus said that the Great Paul K once stated:
>> Hi Dirk,
>>
>> > Or alternatively, is there a way to unread a line when you realize
>> > it's not meant for the current group?
>>
>> You can use fh:seek() to get the position before reading and then set
>> to that position after reading, so the next reading operation starts
>> there.
>
>   That only works if what you are reading from *is* a file.  Anything else
> (io.stdin, a network connection, etc.) won't work as you cannot seek on
> those types of devices.
>
>   Buffering a line works for both seekable and non-seekable data sources.
>
>   -spc (There is ungetc() in C, but you are only guarenteed one character of
>         pushback ... )

It has dawned on me that the specific format I need it for has lines starting
with a number, and if you know that number you know whether the group
is done, so I only need to buffer the number if I use file:read'n' before
file:read().