lua-users home
lua-l archive

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


> It uses information from the byte code header.

Attached is a program that reads this header.
-- list header contents of precompiled chunks
-- typical usage: lua header.lua < luac.out

function byte() return string.byte(io.read(1)) end

-- signature
s=io.read(4)
if s~="\027Lua" then error"stdin is not a Lua precompiled chunk" end

-- version
b=byte()
v=math.floor(b/16).."."..math.fmod(b,16)
io.write("Lua ",v,"\n")
v=tonumber(v)
if v<=5 then return end

-- format
b=byte()
io.write("format version ",b,"\n")

-- endianness
b=byte()
if b==1 then io.write"little endian\n" else io.write"big endian\n" end

-- vm spec
io.write(byte(),"-byte integers\n")
io.write(byte(),"-byte size_t\n")
io.write(byte(),"-byte Instructions\n")
io.write(byte(),"-byte ")
if byte()==0 then io.write("reals\n") else io.write("integers\n") end