lua-users home
lua-l archive

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


On Mon, Apr 1, 2019 at 9:03 AM Matthias wrote:

how to cross-compile Lua byte code for a specific target architecture


There is a tool to convert Lua 5.3 bytecode files from one platform to another.
https://lua-bytecode.github.io/
The converter itself is written in pure Lua (and runs under Fengari),
so you can use it as a stand-alone application after a small modification:
extract .lua file from this web-page
and add few lines of Lua code (to read input file and write output file).
 
 
The converter has the following limitations:
 
1. On each platform sizeof(int) must be either 4 or 8
(this size might be different on source and destination platforms)
 
2. On each platform sizeof(size_t) must be either 4 or 8
(this size might be different on source and destination platforms)
 
3. On each platform Lua 5.3 floating point numbers must be IEEE-754-compatible:
either 32-bit float or 64-bit double
(float size might be different on source and destination platforms)
 
4. On each platform Lua 5.3 integers must be either int32 or int64
(integer size might be different on source and destination platforms)
 
5. Mixed endian platforms are not supported:
each platform must be either little-endian or big-endian
(endianness might be different on source and destination platforms)
 
6. Exotic platforms are not supported:
on each platform endianness of integers must be the same as endianness of floats
 
 
Prior to convert a bytecode file you must determine the "EnBi" (endianness + bitness)
of the destination platform.

How to determine EnBi:
Just open (in the bytecode viewer) any bytecode file created on the destination platform:
the EnBi (string of length 5) will be displayed on the second line.
Even the simplest bytecode would be enough:
run "luac -" with empty stdin and take "luac.out"