diff --git a/lundump.c b/lundump.c index 57a36935..a1519f38 100644 --- a/lundump.c +++ b/lundump.c @@ -1,11 +1,9 @@ /* -** $Id: lundump.c,v 1.47 2002/05/15 18:57:44 roberto Exp roberto $ +** $Id: lundump.c,v 1.40 2002/03/01 01:48:42 lhf Exp lhf $ ** load pre-compiled Lua chunks ** See Copyright Notice in lua.h */ -#include - #include "lua.h" #include "ldebug.h" @@ -14,19 +12,24 @@ #include "lopcodes.h" #include "lstring.h" #include "lundump.h" +#include "lzio.h" -#define LoadByte ezgetc -#define LoadShort (short) LoadInt +#define LoadByte (lu_byte) ezgetc static const char* ZNAME (ZIO* Z) { const char* s=zname(Z); - return (*s=='@') ? s+1 : s; + if (*s=='@' || *s=='=') + return s+1; + else if (*s==LUA_SIGNATURE[0]) + return "binary string"; + else + return s; } static void unexpectedEOZ (lua_State* L, ZIO* Z) { - luaG_runerror(L,"unexpected end of file in `%s'",ZNAME(Z)); + luaG_runerror(L,"unexpected end of file in %s",ZNAME(Z)); } static int ezgetc (lua_State* L, ZIO* Z) @@ -75,6 +78,7 @@ static int LoadInt (lua_State* L, ZIO* Z, int swap) { int x; LoadBlock(L,&x,sizeof(x),Z,swap); + if (x<0) luaG_runerror(L,"bad integer in %s",ZNAME(Z)); return x; } @@ -155,8 +159,10 @@ static void LoadConstants (lua_State* L, Proto* f, ZIO* Z, int swap) case LUA_TSTRING: tsvalue(o)=LoadString(L,Z,swap); break; + case LUA_TNIL: + break; default: - luaG_runerror(L,"bad constant type (%d) in `%s'",ttype(o),ZNAME(Z)); + luaG_runerror(L,"bad constant type (%d) in %s",ttype(o),ZNAME(Z)); break; } } @@ -171,16 +177,16 @@ static Proto* LoadFunction (lua_State* L, TString* p, ZIO* Z, int swap) Proto* f=luaF_newproto(L); f->source=LoadString(L,Z,swap); if (f->source==NULL) f->source=p; f->lineDefined=LoadInt(L,Z,swap); - f->nupvalues=LoadShort(L,Z,swap); - f->numparams=LoadShort(L,Z,swap); - f->is_vararg=LoadShort(L,Z,swap); - f->maxstacksize=LoadShort(L,Z,swap); + f->nupvalues=LoadByte(L,Z); + f->numparams=LoadByte(L,Z); + f->is_vararg=LoadByte(L,Z); + f->maxstacksize=LoadByte(L,Z); LoadLocals(L,f,Z,swap); LoadLines(L,f,Z,swap); LoadConstants(L,f,Z,swap); LoadCode(L,f,Z,swap); #ifndef TRUST_BINARIES - if (!luaG_checkcode(f)) luaG_runerror(L,"bad code in `%s'",ZNAME(Z)); + if (!luaG_checkcode(f)) luaG_runerror(L,"bad code in %s",ZNAME(Z)); #endif return f; } @@ -190,15 +196,15 @@ static void LoadSignature (lua_State* L, ZIO* Z) const char* s=LUA_SIGNATURE; while (*s!=0 && ezgetc(L,Z)==*s) ++s; - if (*s!=0) luaG_runerror(L,"bad signature in `%s'",ZNAME(Z)); + if (*s!=0) luaG_runerror(L,"bad signature in %s",ZNAME(Z)); } static void TestSize (lua_State* L, int s, const char* what, ZIO* Z) { int r=LoadByte(L,Z); if (r!=s) - luaG_runerror(L,"virtual machine mismatch in `%s':\n" - " size of %.20s is %d but read %d",ZNAME(Z),what,s,r); + luaG_runerror(L,"virtual machine mismatch in %s: " + "size of %s is %d but read %d",ZNAME(Z),what,s,r); } #define TESTSIZE(s,w) TestSize(L,s,w,Z) @@ -211,17 +217,17 @@ static int LoadHeader (lua_State* L, ZIO* Z) LoadSignature(L,Z); version=LoadByte(L,Z); if (version>VERSION) - luaG_runerror(L,"`%s' too new:\n" - " read version %d.%d; expected at most %d.%d", + luaG_runerror(L,"%s too new: " + "read version %d.%d; expected at most %d.%d", ZNAME(Z),V(version),V(VERSION)); if (versionLua */ +#define VERSION 0x50 /* last format change was in 5.0 */ +#define VERSION0 0x50 /* last major change was in 5.0 */ /* a multiple of PI for testing native format */ /* multiplying by 1E8 gives non-trivial integer values */ #define TEST_NUMBER 3.14159265358979323846E8 -/* binary files start with Lua */ -#define LUA_SIGNATURE "\033Lua" - #endif