lua-users home
lua-l archive

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


On Tue, Jul 19, 2016 at 1:36 AM, Paul K <paul@zerobrane.com> wrote:
Hi All,

I came across a header generated by Lua 5.1 that has an unexpected
value in one of the fields. In my local install the header has the
following values "1b4c75615100010404040800", but in the case of that
"strange" header the last field value is 04
("1b4c75615100010404040804").

Looking at luaU_header, the last field is
"*h++=(char)(((lua_Number)0.5)==0);        /* is lua_Number integral?
*/". Did I miscalculate the value or does this mean that someone
updated the header to make the field to have the value 4?

Here is how the dump is generated:

string.dump(function() end):sub(1,12):gsub(".", function(s) return
("%02x"):format(s:byte()) end)

And here is luaU_header from 5.1.5:

void luaU_header (char* h)
{
 int x=1;
 memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
 h+=sizeof(LUA_SIGNATURE)-1;
 *h++=(char)LUAC_VERSION;
 *h++=(char)LUAC_FORMAT;
 *h++=(char)*(char*)&x;                /* endianness */
 *h++=(char)sizeof(int);
 *h++=(char)sizeof(size_t);
 *h++=(char)sizeof(Instruction);
 *h++=(char)sizeof(lua_Number);
 *h++=(char)(((lua_Number)0.5)==0);        /* is lua_Number integral? */
}

Paul.


Probably, starting from Lua 5.3 an additional field "sizeof(lua_Integer)"
was inserted between "sizeof(Instruction)" and "sizeof(lua_Number)".

https://www.lua.org/source/5.3/ldump.c.html#DumpHeader