2 ** $Id: lzio.c,v 1.34 2011/07/15 12:35:32 roberto Exp $
3 ** a generic input stream interface
4 ** See Copyright Notice in lua.h
21 int luaZ_fill (ZIO
*z
) {
26 buff
= z
->reader(L
, z
->data
, &size
);
28 if (buff
== NULL
|| size
== 0)
30 z
->n
= size
- 1; /* discount char being returned */
32 return cast_uchar(*(z
->p
++));
36 void luaZ_init (lua_State
*L
, ZIO
*z
, lua_Reader reader
, void *data
) {
45 /* --------------------------------------------------------------- read --- */
46 size_t luaZ_read (ZIO
*z
, void *b
, size_t n
) {
49 if (z
->n
== 0) { /* no bytes in buffer? */
50 if (luaZ_fill(z
) == EOZ
) /* try to read more */
51 return n
; /* no more input; return number of missing bytes */
53 z
->n
++; /* luaZ_fill consumed first byte; put it back */
57 m
= (n
<= z
->n
) ? n
: z
->n
; /* min. between n and z->n */
67 /* ------------------------------------------------------------------------ */
68 char *luaZ_openspace (lua_State
*L
, Mbuffer
*buff
, size_t n
) {
69 if (n
> buff
->buffsize
) {
70 if (n
< LUA_MINBUFFER
) n
= LUA_MINBUFFER
;
71 luaZ_resizebuffer(L
, buff
, n
);