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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! Centralized Lua VM limits and configuration constants.
//!
//! Mirrors Lua 5.5's `luaconf.h` / `llimits.h` design.
//! All magic numbers that control VM behavior are collected here
//! for easy tuning and configuration.
// ===== Stack =====
/// Extra stack slots above frame_top for C function calls, temporaries, etc.
/// Matches Lua 5.5's EXTRA_STACK (5).
pub const EXTRA_STACK: usize = 5;
/// Initial stack capacity for new Lua states.
/// Equivalent to 2 × LUA_MINSTACK (Lua 5.5: LUA_MINSTACK = 20).
pub const BASIC_STACK_SIZE: usize = 2 * LUA_MINSTACK;
/// Minimum guaranteed stack slots available to C functions.
/// Matches Lua 5.5's LUA_MINSTACK.
pub const LUA_MINSTACK: usize = 20;
/// Default maximum stack size (number of slots).
/// Matches Lua 5.5's LUAI_MAXSTACK.
pub const LUAI_MAXSTACK: usize = 1_000_000;
/// Default maximum Lua call-stack depth (number of call frames).
/// This limits how deep pure-Lua calls can nest.
/// Set high by default — the real recursion guard is `LUAI_MAXCSTACK`.
pub const MAX_CALL_DEPTH: usize = 1024;
/// Default maximum C-stack depth (Rust recursion depth).
/// Matches C Lua 5.5's `LUAI_MAXCSTACK` (200).
/// Limits how many times we can recursively enter `lua_execute`,
/// call metamethods, or call C functions.
pub const LUAI_MAXCSTACK: usize = 200;
/// Extra C-stack depth allowance granted during error-handler execution.
/// Allows error handlers and `__close` metamethods to run even after
/// a C-stack overflow.
pub const CSTACKERR: usize = 30;
// ===== Strings =====
/// Maximum length for "short" strings (interned in hash table).
/// Matches Lua 5.5's LUAI_MAXSHORTLEN.
pub const LUAI_MAXSHORTLEN: usize = 40;
// ===== Compiler =====
/// Maximum number of local variables per function.
/// Matches Lua 5.5's MAXVARS.
pub const MAXVARS: usize = 200;
/// Maximum number of upvalues per function.
/// Matches Lua 5.5's MAXUPVAL.
pub const MAXUPVAL: usize = 255;
/// Maximum parser recursion depth (prevents stack overflow in parser).
/// Matches Lua 5.5's MAXCCALLS for the parser.
pub const MAXCCALLS: usize = 200;
/// Maximum index for R/K operand in instructions.
pub const MAXINDEXRK: usize = 255;
/// "No register" sentinel value in the compiler.
pub const NO_REG: u32 = 255;
/// Number of list items to flush per SETLIST instruction in table constructors.
/// Matches Lua 5.5's LFIELDS_PER_FLUSH.
pub const LFIELDS_PER_FLUSH: u32 = 50;
/// Unary operator priority in expression parser.
pub const UNARY_PRIORITY: i32 = 12;
/// Maximum length of source name in error messages.
pub const MAX_SRC_LEN: usize = 59;
// ===== Metamethods =====
/// Maximum depth for __index / __newindex metamethod chains.
/// Prevents infinite loops in metamethod resolution.
/// Matches Lua 5.5's MAXTAGLOOP.
pub const MAXTAGLOOP: usize = 2000;
// ===== Pattern Matching =====
/// Maximum number of captures in `string.find` / `string.gmatch` patterns.
/// Matches Lua 5.5's LUA_MAXCAPTURES.
pub const LUA_MAXCAPTURES: usize = 32;
/// Maximum match recursion depth for pattern matching.
pub const MAXCCALLS_PATTERN: usize = 200;
// ===== String Library =====
/// Maximum string size (1 GB).
pub const MAX_STRING_SIZE: i64 = 1 << 30;
// ===== Concat =====
/// Stack-allocated buffer size for small concatenations.
pub const CONCAT_STACK_BUF_SIZE: usize = 256;
// ===== GC Defaults =====
/// Default GC pause (percentage). Controls how long GC waits before starting
/// a new cycle. 250 = wait until memory is 2.5x the size after last collection.
pub const DEFAULT_GC_PAUSE: i32 = 250;
/// Default GC step multiplier (percentage). Controls how much work GC does
/// per step relative to memory allocation. 200 = collect 2x the allocated speed.
pub const DEFAULT_GC_STEPMUL: i32 = 200;
/// Default minor GC collection multiplier (percentage).
/// Matches C Lua 5.5's LUAI_GENMINORMUL = 20.
/// A young (minor) collection will run after creating GENMINORMUL% new bytes.
pub const DEFAULT_GC_MINORMUL: i32 = 20;
/// Minor-to-major GC transition threshold (percentage).
pub const DEFAULT_GC_MINORMAJOR: i32 = 70;
/// Major-to-minor GC transition threshold (percentage).
pub const DEFAULT_GC_MAJORMINOR: i32 = 50;
/// Maximum number of objects swept per single GC step.
pub const GC_SWEEPMAX: isize = 20;