Is it enough if you can determine the endianness of the system you are running on?
In Lua 5.1 and 5.2 at least, the 7th byte of the bytecode header is 1 for little endian systems and 0 for big endian systems. You can obtain this byte from any Lua script this way:
string.dump(function() end):byte(7)
If you use LuaJIT you can just check the value of:
ffi.abi("le")
Finding this out should be enough to let you write portable code.