This page follows Lua 5.3’s ldump.c, lundump.c,
lundump.h and lopcodes.h (5.3.6). The format is not
documented by the Lua authors. Lua 5.3 added a separate integer type, so the header
checks the sizes of both integers and floats, and stores a sample of each so the
loader can detect a different byte order or float format.
Header
| Offset | Size | Field | Meaning |
|---|---|---|---|
0 | 4 | signature | 1B 4C 75 61. |
4 | 1 | version | 0x53. |
5 | 1 | format | 0, the official format. |
6 | 6 | LUAC_DATA | 19 93 0D 0A 1A 0A, compared byte for byte; a mismatch means a corrupted chunk. |
12 | 1 | sizeof(int) | Bytes in an int. |
13 | 1 | sizeof(size_t) | Bytes in a size_t. |
14 | 1 | sizeof(Instruction) | Bytes in an instruction. |
15 | 1 | sizeof(lua_Integer) | Bytes in an integer. |
16 | 1 | sizeof(lua_Number) | Bytes in a float. |
17 | 8* | LUAC_INT | The integer 0x5678 as a lua_Integer, which reveals the byte order. |
25* | 8* | LUAC_NUM | The float 370.5 as a lua_Number, which reveals the float format. |
33* | 1 | upvalues | Number of upvalues of the main closure. |
* With 8-byte lua_Integer and lua_Number.
There is no endianness byte: the sample integer replaces it.
Basic types
| Type | Encoding |
|---|---|
| byte | One byte. |
| int | sizeof(int) bytes, native byte order. |
| integer | sizeof(lua_Integer) bytes. |
| number | sizeof(lua_Number) bytes. |
| string | A size byte holding the length plus one; 00 means no string; FF means the length plus one follows as a size_t. Then the bytes, with no terminating zero. |
| list of T | An int count, then that many T. |
Function prototype
| Field | Type | Meaning |
|---|---|---|
| source | string | Source name; when absent, the parent function’s source is used. |
| linedefined | int | First line. |
| lastlinedefined | int | Last line. |
| numparams | byte | Fixed parameters. |
| is_vararg | byte | Whether the function takes .... |
| maxstacksize | byte | Registers needed. |
| code | list of Instruction | 4 bytes each. |
| constants | list of constant | Below. |
| upvalues | list of (byte, byte) | instack and idx, one byte each. |
| protos | list of function | Nested prototypes. |
| lineinfo | list of int | Line of each instruction. |
| locvars | list of (string, int, int) | Name, start pc, end pc. |
| upvalue names | list of string | Upvalue names in order. |
Constants
| Tag byte | Type | Then |
|---|---|---|
0x00 | nil | nothing |
0x01 | boolean | one byte |
0x03 | float (LUA_TNUMFLT) | a number |
0x13 | integer (LUA_TNUMINT) | an integer |
0x04 | short string (LUA_TSHRSTR) | a string |
0x14 | long string (LUA_TLNGSTR) | a string |
The tag is the basic type in the low four bits and a variant in bits 4–5.
Instructions
| Mode | Bits 31–23 | Bits 22–14 | Bits 13–6 | Bits 5–0 |
|---|---|---|---|---|
iABC | B (9) | C (9) | A (8) | opcode (6) |
iABx | Bx (18) | A (8) | opcode (6) | |
iAsBx | sBx (18), stored + 131,071 | A (8) | opcode (6) | |
iAx | Ax (26) | opcode (6) | ||
RK(x) is constant x − 256 when bit 8 is set, otherwise
register x. SETLIST’s batch size FPF is
LFIELDS_PER_FLUSH (50, per 5.3’s
lopcodes.h
on lua.org, read 2026-11-12). Every skip assumes
the next instruction is a jump.
| Op | Name | Mode | Action |
|---|---|---|---|
| 0 | MOVE | A B | R(A) := R(B) |
| 1 | LOADK | A Bx | R(A) := Kst(Bx) |
| 2 | LOADKX | A | R(A) := Kst(extra arg) |
| 3 | LOADBOOL | A B C | R(A) := (Bool)B; if C, skip next |
| 4 | LOADNIL | A B | R(A), …, R(A+B) := nil |
| 5 | GETUPVAL | A B | R(A) := UpValue[B] |
| 6 | GETTABUP | A B C | R(A) := UpValue[B][RK(C)] |
| 7 | GETTABLE | A B C | R(A) := R(B)[RK(C)] |
| 8 | SETTABUP | A B C | UpValue[A][RK(B)] := RK(C) |
| 9 | SETUPVAL | A B | UpValue[B] := R(A) |
| 10 | SETTABLE | A B C | R(A)[RK(B)] := RK(C) |
| 11 | NEWTABLE | A B C | R(A) := {}; B is the initial array size and C the initial hash size, each a “floating point byte” (below); when both are 0 the table is left empty |
| 12 | SELF | A B C | R(A+1) := R(B); R(A) := R(B)[RK(C)] |
| 13 | ADD | A B C | R(A) := RK(B) + RK(C) |
| 14 | SUB | A B C | R(A) := RK(B) − RK(C) |
| 15 | MUL | A B C | R(A) := RK(B) × RK(C) |
| 16 | MOD | A B C | R(A) := RK(B) % RK(C) |
| 17 | POW | A B C | R(A) := RK(B) ^ RK(C) |
| 18 | DIV | A B C | R(A) := RK(B) / RK(C) |
| 19 | IDIV | A B C | R(A) := RK(B) // RK(C) |
| 20 | BAND | A B C | R(A) := RK(B) & RK(C) |
| 21 | BOR | A B C | R(A) := RK(B) | RK(C) |
| 22 | BXOR | A B C | R(A) := RK(B) ~ RK(C) |
| 23 | SHL | A B C | R(A) := RK(B) << RK(C) |
| 24 | SHR | A B C | R(A) := RK(B) >> RK(C) |
| 25 | UNM | A B | R(A) := −R(B) |
| 26 | BNOT | A B | R(A) := ~R(B) |
| 27 | NOT | A B | R(A) := not R(B) |
| 28 | LEN | A B | R(A) := length of R(B) |
| 29 | CONCAT | A B C | R(A) := R(B) .. … .. R(C) |
| 30 | JMP | A sBx | pc += sBx; if A, close upvalues at or above R(A−1) |
| 31 | EQ | A B C | if (RK(B) == RK(C)) ~= A then skip next |
| 32 | LT | A B C | if (RK(B) < RK(C)) ~= A then skip next |
| 33 | LE | A B C | if (RK(B) <= RK(C)) ~= A then skip next |
| 34 | TEST | A C | if not (R(A) <=> C) then skip next |
| 35 | TESTSET | A B C | if R(B) <=> C then R(A) := R(B) else skip next |
| 36 | CALL | A B C | R(A), …, R(A+C−2) := R(A)(R(A+1), …, R(A+B−1)); B = 0 means B = top (arguments up to the top); C = 0 means top is set to last_result + 1, so the next open instruction (CALL, RETURN, SETLIST) may use it |
| 37 | TAILCALL | A B C | return R(A)(R(A+1), …, R(A+B−1)) |
| 38 | RETURN | A B | return R(A), …, R(A+B−2); B = 0 means return up to the top |
| 39 | FORLOOP | A sBx | R(A) += R(A+2); if within R(A+1), pc += sBx and R(A+3) := R(A) |
| 40 | FORPREP | A sBx | R(A) −= R(A+2); pc += sBx |
| 41 | TFORCALL | A C | R(A+3), …, R(A+2+C) := R(A)(R(A+1), R(A+2)) |
| 42 | TFORLOOP | A sBx | if R(A+1) ~= nil then R(A) := R(A+1); pc += sBx |
| 43 | SETLIST | A B C | R(A)[(C−1) × FPF + i] := R(A+i), 1 ≤ i ≤ B; B = 0 means the real B is the top; C = 0 means the next instruction is an EXTRAARG holding the real C |
| 44 | CLOSURE | A Bx | R(A) := closure(KPROTO[Bx]) |
| 45 | VARARG | A B | R(A), …, R(A+B−2) := vararg; B = 0 means use the actual number of varargs and set top (like CALL with C = 0) |
| 46 | EXTRAARG | Ax | A larger argument for the previous instruction. After LOADKX the next instruction is always an EXTRAARG |
Floating point byte (NEWTABLE B and C)
The parser stores the constructor’s array count and hash count with
luaO_int2fb and the VM reads them back with luaO_fb2int
(lobject.c). A “floating point byte” is eeeeexxx: when
eeeee is 0 the value is xxx; otherwise it is
(1xxx)2 × 2eeeee−1, that is
((x & 7) + 8) << (e − 1). luaO_int2fb returns the
number itself below 8, otherwise it divides by 16 (rounding up) while the value is at
least 128, adding 4 to the exponent each time, then by 2 (rounding up) while it is at
least 16, adding 1, and returns ((e + 1) << 3) | (x − 8). The encoded
size is therefore never smaller than the real one. Example: 100 becomes 100 → 50 → 25 →
13 after three halvings (e = 3), so the byte is (4 << 3) | 5 = 0x25,
which decodes to 13 << 3 = 104.
Operand modes (luaP_opmodes)
lopcodes.c holds one byte per opcode, built by
opmode(t, a, b, c, m) as
(t << 7) | (a << 6) | (b << 4) | (c <<2) | m: bits 0–1
the format, bits 2–3 the C argument mode, bits 4–5 the B argument mode, bit 6 “sets
register A” and bit 7 “is a test” (the next instruction must be a jump). The argument
modes (enum OpArgMask) are N, argument not used;
U, used (a number, count or flag); R, a register or a jump
offset; K, a constant or register/constant (RK).
| Ops | Names | Format | B | C | Sets A | Test |
|---|---|---|---|---|---|---|
| 0 | MOVE | iABC | R | N | yes | |
| 1 | LOADK | iABx | K | N | yes | |
| 2 | LOADKX | iABx | N | N | yes | |
| 3 | LOADBOOL | iABC | U | U | yes | |
| 4–5 | LOADNIL, GETUPVAL | iABC | U | N | yes | |
| 6 | GETTABUP | iABC | U | K | yes | |
| 7 | GETTABLE | iABC | R | K | yes | |
| 8 | SETTABUP | iABC | K | K | ||
| 9 | SETUPVAL | iABC | U | N | ||
| 10 | SETTABLE | iABC | K | K | ||
| 11 | NEWTABLE | iABC | U | U | yes | |
| 12 | SELF | iABC | R | K | yes | |
| 13–24 | ADD, SUB, MUL, MOD, POW, DIV, IDIV, BAND, BOR, BXOR, SHL, SHR | iABC | K | K | yes | |
| 25–28 | UNM, BNOT, NOT, LEN | iABC | R | N | yes | |
| 29 | CONCAT | iABC | R | R | yes | |
| 30 | JMP | iAsBx | R | N | ||
| 31–33 | EQ, LT, LE | iABC | K | K | yes | |
| 34 | TEST | iABC | N | U | yes | |
| 35 | TESTSET | iABC | R | U | yes | yes |
| 36–37 | CALL, TAILCALL | iABC | U | U | yes | |
| 38 | RETURN | iABC | U | N | ||
| 39–40 | FORLOOP, FORPREP | iAsBx | R | N | yes | |
| 41 | TFORCALL | iABC | N | U | ||
| 42 | TFORLOOP | iAsBx | R | N | yes | |
| 43 | SETLIST | iABC | U | U | ||
| 44 | CLOSURE | iABx | U | N | yes | |
| 45 | VARARG | iABC | U | N | yes | |
| 46 | EXTRAARG | iAx | U | U |
Source: luaP_opmodes in lopcodes.c and the mask comment in
lopcodes.h, Lua 5.3.6 (raw files of the v5.3.6 tag).
What the loader rejects
Every rule below makes luaU_undump fail with a syntax error; message wording is
not part of the format. Source: Lua 5.3.6 lundump.c, lundump.h,
ldo.c, lmem.h and llimits.h, raw files of the
v5.3.6 tag.
- Mode: before the loader runs,
f_parser(ldo.c) refuses a binary chunk when the mode string given toloadorlua_loaddoes not containb. - Header, checked in this order, each field refused if it differs: the signature after its first byte (
Lua); the version byte (0x53); the format byte (0);LUAC_DATA(19 93 0D 0A 1A 0A); the size bytes ofint,size_t,Instruction,lua_Integerandlua_Number, each equal to the host’s; the integerLUAC_INT(0x5678) read in the host’s byte order, which tests the byte order; the numberLUAC_NUM(370.5), which tests the floating-point format. A chunk is readable only by a build with the same sizes, byte order and float format. - Truncation: any read that does not get all its bytes is refused.
- Integers: counts and line numbers (
int) are not range-checked by the loader: a negative value is not refused there, and is used as a huge size when the array is allocated (the allocator’s “too big” test only applies whenintis as wide assize_t), so the load then fails for lack of memory or misbehaves. - Constants: an unknown tag byte is not refused in a normal build (
lua_assert( 0 )does nothing unless built with assertions): the constant stays nil. A string constant with size 0 is accepted and gives a null string pointer; there is no rule that a constant string must be present. - Upvalue names: the debug section’s count is used as the loop limit without comparing it with the upvalue count; a larger count is not rejected by the loader.
- Nesting: no depth limit in the loader (
LUAI_MAXCCALLSis 200 inllimits.hbutLoadFunctiondoes not use it). - Code: not verified;
luai_verifycodeis empty. - Chunk name: never a cause of refusal; used only in messages: a leading
@or=is dropped, a name beginning with the signature byte shows as “binary string”, any other is shown as is.
String tags and length
A string is a size byte (0xFF means a size_t follows, in the host’s size and order), then the bytes. The size counts the trailing zero byte, and 0 means no string. The loader treats a constant with tag 0x04 or 0x14 in exactly the same way and ignores the tag: it makes a short string when the length (size − 1) is at most LUAI_MAXSHORTLEN, and a long string otherwise. LUAI_MAXSHORTLEN is 40 (llimits.h 5.3.6, line 177, #define LUAI_MAXSHORTLEN 40 under #if !defined, re-read from the raw file). The tag a dumper writes is that of the string it dumps (ldump.c writes the constant’s own type tag), but a chunk with the other tag still loads, and the string’s kind in the loaded function follows its length, not the tag. (lstring.c, which creates the strings, was not re-read here.)
Stripped chunks
luac -s and string.dump(f, true) pass strip to
luaU_dump. In ldump.c (5.3.6), with strip set, every
function’s source is written as no string (and so is a source equal to its
parent’s even without strip; the loader then reuses the parent’s source), and
lineinfo, locvars and the upvalue-name list are each written
with a count of 0. Header, code, constants, upvalue descriptors and nested prototypes are
unchanged, and the header’s upvalue-count byte still holds the real count.
On loading, a function with no source reuses its parent’s (LoadFunction).
luaU_undump calls it for the main function with a parent source of
NULL, so in a stripped chunk the main function’s source is empty
(null, no name), and so is that of every nested function that also had none.
Example
1B 4C 75 61 53 00 signature, version 5.3, format 0
19 93 0D 0A 1A 0A LUAC_DATA
04 08 04 08 08 sizes: int, size_t, Instruction, lua_Integer, lua_Number
78 56 00 00 00 00 00 00 LUAC_INT 0x5678 (little-endian)
00 00 00 00 00 28 77 40 LUAC_NUM 370.5 (0x4077280000000000)
01 main closure has 1 upvalue
0B 40 68 65 6C 6C 6F 2E 6C 75 61 source "@hello.lua" (length 10, stored as 11)
Sizes and the source name are illustrative.
Sources
Lua 5.3.6 source (lua.org and the
lua/lua repository):
lundump.c (checkHeader, LoadFunction, constants,
strings), lundump.h (LUAC_DATA, LUAC_INT,
LUAC_NUM, LUAC_VERSION, LUAC_FORMAT),
lobject.h (constant tags and variant bits) and lopcodes.h
(field sizes, BITRK, MAXARG_sBx, every opcode and its
comment and notes). The value of 370.5 as bytes is worked out from IEEE 754. The
operand-mode, floating-point-byte and stripping sections come from the raw
v5.3.6 files lopcodes.c, lopcodes.h,
lobject.c (luaO_int2fb, luaO_fb2int),
lparser.c (the constructor sets B and C), lvm.c
(OP_NEWTABLE, luaH_resize(L, t, array, hash)),
ldump.c and lundump.c.