Skip to content

Lua 5.x bytecode dump format

viruscamp edited this page Apr 30, 2018 · 2 revisions
lua-5.1 = header proto
    header = ESC 'Lua' versionB formatB endianB size_int_B size_size_t_B
            size_Instruction_B size_number_B integralB
        versionB = 0x51
    proto = fheader instructions constants protos lineinfos locals upvals
        fheader = string(proto_name) lineDefinedW lastLineDefinedW nupsB
                numparamsB varargB maxstacksizeB
        instructions = sizeInstrctionsW instructionW*
        constants = sizekW constant*
            constant = constTypeB { string | numberW }
        protos = sizepW proto*
        lineinfos = sizelineinfoW lineinfoW*
        locals = sizeW local*
            local = string(local_name) startpcW endpcW
        upvals = sizeW string(upval_name)*
    string = lenW strB*

lua-5.2 = header proto
    header = ESC 'Lua' versionB formatB endianB size_int_B size_size_t_B
            size_Instruction_B size_number_B integralB LUAC_TAIL
        versionB = 0x52
        LUAC_TAIL = \0x19\0x93\r\n\0x1a\n
    proto = fheader instructions constants protos upvals debug
        fheader = lineDefinedW lastLineDefinedW numparamsB varargB maxstacksizeB
        instructions = sizeInstrctionsW instructionW*
        constants = sizekW constant*
            constant = constTypeB { string | numberW }
        protos = sizepW proto*
        upvals = sizeW upval*
            upval = instackB idxB
        debug = string(proto_name) lineinfos locals upval_names
            lineinfos = sizelineinfoW lineinfoW*
            locals = sizeW local*
                local = string(local_name) startpcW endpcW
            upval_names = sizeW string(upval_name)*
    string = lenW strB*

lua-5.3 = header proto
    header = ESC 'Lua' versionB formatB LUAC_DATA size_int_B size_size_t_B
            size_Instruction_B size_Integer_B size_Number_B
            endiannes_bytes float_format global_upval_sizeB
        versionB = 0x53
        LUAC_DATA = \0x19\0x93\r\n\0x1a\n
        endiannes_bytes = Integer of 0x5678 (depends on endianness and size_Integer_B)
        float_format = Number of 370.5 (depends on endianness and size_Number_B)
    proto = fheader instructions constants upvals protos debug
        fheader = string(proto_name) lineDefinedW lastLineDefinedW numparamsB
                varargB maxstacksizeB
        instructions = sizeInstrctionsW instructionW*
        constants = sizekW constant*
            constant = constTypeB { string | Integer | Number }
        upvals = sizeW upval*
            upval = instackB idxB
        protos = sizepW proto*
        debug = lineinfos locals upval_names
            lineinfos = sizelineinfoW lineinfoW*
            locals = sizeW local*
                local = string(local_name) startpcW endpcW
            upval_names = sizeW string(upval_name)*
    string = { lenB(lenB < 0xFF) | 0xFF lenW } strB*