aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lzio.c9
-rw-r--r--lzio.h5
2 files changed, 10 insertions, 4 deletions
diff --git a/lzio.c b/lzio.c
index a09dbdad..24826f68 100644
--- a/lzio.c
+++ b/lzio.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.c,v 1.30 2005/05/17 19:49:15 roberto Exp roberto $ 2** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp roberto $
3** a generic input stream interface 3** a generic input stream interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -22,10 +22,14 @@ int luaZ_fill (ZIO *z) {
22 size_t size; 22 size_t size;
23 lua_State *L = z->L; 23 lua_State *L = z->L;
24 const char *buff; 24 const char *buff;
25 if (z->eoz) return EOZ;
25 lua_unlock(L); 26 lua_unlock(L);
26 buff = z->reader(L, z->data, &size); 27 buff = z->reader(L, z->data, &size);
27 lua_lock(L); 28 lua_lock(L);
28 if (buff == NULL || size == 0) return EOZ; 29 if (buff == NULL || size == 0) {
30 z->eoz = 1; /* avoid calling reader function next time */
31 return EOZ;
32 }
29 z->n = size - 1; 33 z->n = size - 1;
30 z->p = buff; 34 z->p = buff;
31 return char2int(*(z->p++)); 35 return char2int(*(z->p++));
@@ -51,6 +55,7 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
51 z->data = data; 55 z->data = data;
52 z->n = 0; 56 z->n = 0;
53 z->p = NULL; 57 z->p = NULL;
58 z->eoz = 0;
54} 59}
55 60
56 61
diff --git a/lzio.h b/lzio.h
index 07365ad1..36a00900 100644
--- a/lzio.h
+++ b/lzio.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp roberto $ 2** $Id: lzio.h,v 1.22 2009/05/18 17:26:25 roberto Exp roberto $
3** Buffered streams 3** Buffered streams
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -59,9 +59,10 @@ LUAI_FUNC int luaZ_lookahead (ZIO *z);
59struct Zio { 59struct Zio {
60 size_t n; /* bytes still unread */ 60 size_t n; /* bytes still unread */
61 const char *p; /* current position in buffer */ 61 const char *p; /* current position in buffer */
62 lua_Reader reader; 62 lua_Reader reader; /* reader function */
63 void* data; /* additional data */ 63 void* data; /* additional data */
64 lua_State *L; /* Lua state (for reader) */ 64 lua_State *L; /* Lua state (for reader) */
65 int eoz; /* true if reader has no more data */
65}; 66};
66 67
67 68