why luaZ_fill discount char being returned

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

why luaZ_fill discount char being returned

yang chao
luaZ_fill discount the byte ,but luaZ_read put it back; it seems unuseful;
why code do not write like this:
int luaZ_fill (ZIO *z) {
  ....
  z->n = size - 1;  /* discount char being returned */
  z->p = buff;
  return cast_uchar(*(z->p));
}
size_t luaZ_read (ZIO *z, void *b, size_t n) {
  while (n) {
    size_t m;
    if (z->n == 0) {  /* no bytes in buffer? */
      if (luaZ_fill(z) == EOZ)  /* try to read more */
        return n;  /* no more input; return number of missing bytes */
      //else {
      //  z->n++;  /* luaZ_fill consumed first byte; put it back */
      //  z->p--;
      //}
    }
    ....
  }
  return 0;
}
why need discount and put it back ?
Reply | Threaded
Open this post in threaded view
|

Re: why luaZ_fill discount char being returned

Roberto Ierusalimschy
> luaZ_fill discount the byte ,but luaZ_read put it back; it seems unuseful;
> why code do not write like this:
>
> [...]
>
> why need discount and put it back ?

'luaZ_fill' is also used by the macro 'zgetc', which needs that
"discount".

-- Roberto