summaryrefslogtreecommitdiff
path: root/src/bytecodeparser.js
blob: 595158e318a7bb88a757cf1bb292da8d5afa1d44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"use strict";

const DataView = require('buffer-dataview');

/**
 * Parse Lua 5.3 bytecode
 */
class BytecodeParser {

    constructor(dataView) {
        this.dataView = dataView;
        this.offset = 0;
    }

    _read(offset, nbytes) {
        let bytes = new Uint8Array(nbytes);

        for (let i = 0; i < nbytes; i++)
            bytes[i] = this.dataView.getUint8(offset, true);

        return bytes.length === 1 ? bytes[0] : bytes;
    }

    readByte() {
        return read(this.offset++, 1);
    }

}