From 4b2e71ddb674c3bb22f549743721155ddaeb9b5d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 25 Aug 2003 17:00:50 -0300 Subject: [PATCH] ZIO passes Lua state to chunk reader --- lapi.c | 4 ++-- lzio.c | 7 ++++--- lzio.h | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lapi.c b/lapi.c index 2a8283a4..966f72ec 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.241 2003/08/15 13:48:53 roberto Exp roberto $ +** $Id: lapi.c,v 1.242 2003/08/25 19:51:54 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -718,7 +718,7 @@ LUA_API int lua_load (lua_State *L, lua_Chunkreader reader, void *data, int c; lua_lock(L); if (!chunkname) chunkname = "?"; - luaZ_init(&z, reader, data); + luaZ_init(L, &z, reader, data); c = luaZ_lookahead(&z); status = luaD_protectedparser(L, &z, (c == LUA_SIGNATURE[0]), chunkname); lua_unlock(L); diff --git a/lzio.c b/lzio.c index 4ce47161..f3e1dcf6 100644 --- a/lzio.c +++ b/lzio.c @@ -1,5 +1,5 @@ /* -** $Id: lzio.c,v 1.24 2003/03/20 16:00:56 roberto Exp roberto $ +** $Id: lzio.c,v 1.25 2003/08/25 19:51:54 roberto Exp roberto $ ** a generic input stream interface ** See Copyright Notice in lua.h */ @@ -18,7 +18,7 @@ int luaZ_fill (ZIO *z) { size_t size; - const char *buff = z->reader(NULL, z->data, &size); + const char *buff = z->reader(z->L, z->data, &size); if (buff == NULL || size == 0) return EOZ; z->n = size - 1; z->p = buff; @@ -37,7 +37,8 @@ int luaZ_lookahead (ZIO *z) { } -void luaZ_init (ZIO *z, lua_Chunkreader reader, void *data) { +void luaZ_init (lua_State *L, ZIO *z, lua_Chunkreader reader, void *data) { + z->L = L; z->reader = reader; z->data = data; z->n = 0; diff --git a/lzio.h b/lzio.h index d2a99071..bcf11e45 100644 --- a/lzio.h +++ b/lzio.h @@ -1,5 +1,5 @@ /* -** $Id: lzio.h,v 1.15 2003/03/20 16:00:56 roberto Exp roberto $ +** $Id: lzio.h,v 1.16 2003/08/25 19:51:54 roberto Exp roberto $ ** Buffered streams ** See Copyright Notice in lua.h */ @@ -20,7 +20,7 @@ typedef struct Zio ZIO; #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) -void luaZ_init (ZIO *z, lua_Chunkreader reader, void *data); +void luaZ_init (lua_State *L, ZIO *z, lua_Chunkreader reader, void *data); size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ int luaZ_lookahead (ZIO *z); @@ -53,6 +53,7 @@ struct Zio { const char *p; /* current position in buffer */ lua_Chunkreader reader; void* data; /* additional data */ + lua_State *L; /* Lua state (for reader) */ };