-
-
Notifications
You must be signed in to change notification settings - Fork 182
/
lua53.hexpat
107 lines (92 loc) · 2.06 KB
/
lua53.hexpat
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma description Lua 5.3 bytecode
import std.io;
import type.base;
namespace impl {
fn format_LuaString(auto string) {
if (string.size == 0) {
return "None";
}
return std::format("\"{}\"", string.data);
};
fn format_Constant(auto constant) {
return constant.data;
};
fn format_Version(auto ver) {
return std::format("Ver. {}.{}", ver.major, ver.minor);
};
}
using LuaFunction;
bitfield Version {
minor : 4;
major : 4;
} [[format("impl::format_Version")]];
struct LuaBinaryHeader {
char magic[4];
Version version_number;
u8 format_version;
char LUAC_DATA[6];
u8 size_of_int;
u8 size_of_size_t;
u8 size_of_Instruction;
u8 size_of_lua_Integer;
u8 sizeof_lua_Number;
type::Hex<u64> LUAC_INT;
double LUAC_NUM;
};
struct LuaString {
u8 size;
if (size > 0) {
char data[size-1];
}
}[[format("impl::format_LuaString")]];
struct LuaConstant {
u8 type;
if (type == 0) { // LUA_TNIL
// NULL
} else if (type == 1) { // LUA_TBOOLEAN
u8 data;
} else if (type == 3) { // LUA_TNUMFLT
double data;
} else if (type == 0x13) { // LUA_TNUMINT
u64 data;
} else if (type == 4 || type == 0x14 ) { // LUA_TSHRSTR LUA_TLNGSTR
LuaString data;
}
}[[format("impl::format_Constant")]];
struct LuaUpvalue {
u8 instack;
u8 idx;
};
struct Vector<T> {
u32 size;
T values[size];
};
struct LocalVar {
LuaString varname;
u32 startpc;
u32 endpc;
};
struct LuaDebugInfo {
Vector<u32> lineInfo;
Vector<LocalVar> local_vars;
Vector<LuaString> upvalues;
};
struct LuaFunction {
LuaString source;
u32 line_defined;
u32 last_line_defined;
u8 number_of_parameters;
u8 is_vararg;
u8 maxstacksize;
Vector<u32> code;
Vector<LuaConstant> constants;
Vector<LuaUpvalue> upvalues;
Vector<LuaFunction> protos;
LuaDebugInfo debugInfo;
};
struct LuaFile {
LuaBinaryHeader header;
u8 sizeupvalues;
LuaFunction func;
};
LuaFile file @ 0;