diff --git a/ldump.c b/ldump.c index fbadbcc9..f848b669 100644 --- a/ldump.c +++ b/ldump.c @@ -196,7 +196,7 @@ static void dumpFunction (DumpState *D, const Proto *f, TString *psource) { static void dumpHeader (DumpState *D) { dumpLiteral(D, LUA_SIGNATURE); - dumpInt(D, LUAC_VERSION); + dumpByte(D, LUAC_VERSION); dumpByte(D, LUAC_FORMAT); dumpLiteral(D, LUAC_DATA); dumpByte(D, sizeof(Instruction)); diff --git a/loadlib.c b/loadlib.c index ddfecca9..c0ec9a13 100644 --- a/loadlib.c +++ b/loadlib.c @@ -69,7 +69,7 @@ static const char *const CLIBS = "_CLIBS"; /* ** Special type equivalent to '(void*)' for functions in gcc -** (to supress warnings when converting function pointers) +** (to suppress warnings when converting function pointers) */ typedef void (*voidf)(void); diff --git a/lundump.c b/lundump.c index 17364999..d6b249d5 100644 --- a/lundump.c +++ b/lundump.c @@ -276,7 +276,7 @@ static void fchecksize (LoadState *S, size_t size, const char *tname) { static void checkHeader (LoadState *S) { /* skip 1st char (already read and checked) */ checkliteral(S, &LUA_SIGNATURE[1], "not a binary chunk"); - if (loadInt(S) != LUAC_VERSION) + if (loadByte(S) != LUAC_VERSION) error(S, "version mismatch"); if (loadByte(S) != LUAC_FORMAT) error(S, "format mismatch"); diff --git a/lundump.h b/lundump.h index 5b05fed4..2df6923e 100644 --- a/lundump.h +++ b/lundump.h @@ -18,7 +18,12 @@ #define LUAC_INT 0x5678 #define LUAC_NUM cast_num(370.5) -#define LUAC_VERSION LUA_VERSION_NUM +/* +** Encode major-minor version in one byte, one nibble for each +*/ +#define MYINT(s) (s[0]-'0') /* assume one-digit numbers */ +#define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) + #define LUAC_FORMAT 0 /* this is the official format */ /* load one chunk; from lundump.c */ diff --git a/testes/calls.lua b/testes/calls.lua index 0141ffa4..1701f155 100644 --- a/testes/calls.lua +++ b/testes/calls.lua @@ -422,9 +422,9 @@ assert((function (a) return a end)() == nil) print("testing binary chunks") do - local header = string.pack("c4BBBc6BBBj", + local header = string.pack("c4BBc6BBBj", "\27Lua", -- signature - (504 >> 7) & 0x7f, (504 & 0x7f) | 0x80, -- version 5.4 (504) + 0x54, -- version 5.4 (0x54) 0, -- format "\x19\x93\r\n\x1a\n", -- data 4, -- size of instruction