lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I found that the LoadHeader function gave very undescriptive error,
which makes it hard to establish what is wrong with the header (and
hence the compiled code). My modified LoadHeader function:

static void LoadHeader(LoadState* S)
{
 char h[LUAC_HEADERSIZE];
 char s[LUAC_HEADERSIZE];
 int i;
 const char* bad = 0;
 luaU_header(h);
 LoadBlock(S,s,LUAC_HEADERSIZE);

 for(i = 0; i < LUAC_HEADERSIZE; ++i)
 {
 	if(h[i] != s[i])
 	{
		switch(i)
		{
		case LUAC_HEADERSIZE - 1:
			bad = "lua_Number integralness";
			break;
		case LUAC_HEADERSIZE - 2:
			bad = "lua_Number size";
			break;
		case LUAC_HEADERSIZE - 3:
			bad = "Instruction size";
			break;
		case LUAC_HEADERSIZE - 4:
			bad = "size_t size";
			break;
		case LUAC_HEADERSIZE - 5:
			bad = "int size";
			break;
		case LUAC_HEADERSIZE - 6:
			bad = "endianness";
			break;
		case LUAC_HEADERSIZE - 7:
			bad = "format";
			break;
		case LUAC_HEADERSIZE - 8:
			bad = "version";
			break;
		default:
			luaO_pushfstring(S->L,"%s: bad header in precompiled chunk
(signature byte %d)",S->name,i);
			luaD_throw(S->L,LUA_ERRSYNTAX);
			break;
		}
	 if(bad != 0)
		luaO_pushfstring(S->L,"%s: bad header in precompiled chunk (%s is
%d, should be %d)",S->name,bad,(int)s[i],(int)h[i]);
	 else
		 luaO_pushfstring(S->L,"%s: bad header in precompiled chunk",S->name);
	 luaD_throw(S->L,LUA_ERRSYNTAX);
	}
 }
}