diff --git a/lapi.c b/lapi.c index 7e88dc03..680ce9e1 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.193 2002/05/27 20:35:40 roberto Exp roberto $ +** $Id: lapi.c,v 1.194 2002/06/03 17:46:34 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -564,13 +564,15 @@ LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errf) { LUA_API int lua_load (lua_State *L, lua_Getblock getblock, void *ud, - int binary, const char *chunkname) { + const char *chunkname) { ZIO z; int status; + int c; lua_lock(L); if (!chunkname) chunkname = "?"; luaZ_init(&z, getblock, ud, chunkname); - status = luaD_protectedparser(L, &z, binary); + c = luaZ_lookahead(&z); + status = luaD_protectedparser(L, &z, (c == LUA_SIGNATURE[0])); lua_unlock(L); return status; } diff --git a/lua.h b/lua.h index 6277b98c..c2456039 100644 --- a/lua.h +++ b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.134 2002/05/23 20:29:05 roberto Exp roberto $ +** $Id: lua.h,v 1.135 2002/06/03 17:46:34 roberto Exp roberto $ ** Lua - An Extensible Extension Language ** Tecgraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil ** e-mail: info@lua.org @@ -182,7 +182,7 @@ LUA_API void lua_setmetatable (lua_State *L, int objindex); LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults); LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errf); LUA_API int lua_load (lua_State *L, lua_Getblock getblock, void *ud, - int binary, const char *chunkname); + const char *chunkname); /* @@ -291,9 +291,6 @@ LUA_API int lua_pushupvalues (lua_State *L); ** ======================================================================= */ -/* binary files start with Lua */ -#define LUA_SIGNATURE "\033Lua" - /* formats for Lua numbers */ #ifndef LUA_NUMBER_SCAN #define LUA_NUMBER_SCAN "%lf" diff --git a/lundump.h b/lundump.h index 6c647acf..473da103 100644 --- a/lundump.h +++ b/lundump.h @@ -1,5 +1,5 @@ /* -** $Id: lundump.h,v 1.23 2001/07/12 19:34:03 roberto Exp roberto $ +** $Id: lundump.h,v 1.24 2002/06/03 17:46:34 roberto Exp roberto $ ** load pre-compiled Lua chunks ** See Copyright Notice in lua.h */ @@ -24,4 +24,7 @@ int luaU_endianness (void); /* multiplying by 1E8 gives non-trivial integer values */ #define TEST_NUMBER 3.14159265358979323846E8 +/* binary files start with Lua */ +#define LUA_SIGNATURE "\033Lua" + #endif diff --git a/lzio.c b/lzio.c index 3e3610c9..fe0e18cd 100644 --- a/lzio.c +++ b/lzio.c @@ -1,5 +1,5 @@ /* -** $Id: lzio.c,v 1.16 2002/04/29 12:37:41 roberto Exp roberto $ +** $Id: lzio.c,v 1.17 2002/06/03 17:46:34 roberto Exp roberto $ ** a generic input stream interface ** See Copyright Notice in lua.h */ @@ -24,6 +24,17 @@ int luaZ_fill (ZIO *z) { } +int luaZ_lookahead (ZIO *z) { + if (z->n == 0) { + int c = luaZ_fill(z); + if (c == EOZ) return c; + z->n++; + z->p--; + } + return *z->p; +} + + void luaZ_init (ZIO *z, lua_Getblock getblock, void *ud, const char *name) { z->getblock = getblock; z->ud = ud; diff --git a/lzio.h b/lzio.h index 9ffbbf8a..e24c4f0e 100644 --- a/lzio.h +++ b/lzio.h @@ -1,5 +1,5 @@ /* -** $Id: lzio.h,v 1.9 2002/04/29 12:37:41 roberto Exp roberto $ +** $Id: lzio.h,v 1.10 2002/06/03 17:46:34 roberto Exp roberto $ ** Buffered streams ** See Copyright Notice in lua.h */ @@ -26,6 +26,7 @@ typedef struct zio ZIO; void luaZ_init (ZIO *z, lua_Getblock getblock, void *ud, const char *name); size_t luaZ_zread (ZIO* z, void* b, size_t n); /* read next n bytes */ +int luaZ_lookahead (ZIO *z); /* --------- Private Part ------------------ */