You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LuaBridge3 exposes several compile-time configuration macros. Each macro can be overridden by defining it **before** including any LuaBridge header, or by passing it as a compiler flag (e.g. `-DLUABRIDGE_SAFE_STACK_CHECKS=0`).
1731
+
1732
+
6.1 - LUABRIDGE_SAFE_STACK_CHECKS
1733
+
----------------------------------
1734
+
1735
+
**Default: `1` (enabled)**
1736
+
1737
+
When enabled, every `Stack<T>::push` operation calls `lua_checkstack` before pushing a value. This prevents silent stack overflows when the Lua stack is exhausted.
1738
+
1739
+
Disable this flag only when you are certain that the Lua stack will never overflow and you need to squeeze out the last bit of performance:
1740
+
1741
+
```cpp
1742
+
#define LUABRIDGE_SAFE_STACK_CHECKS 0
1743
+
#include <LuaBridge/LuaBridge.h>
1744
+
```
1745
+
1746
+
6.2 - LUABRIDGE_STRICT_STACK_CONVERSIONS
1747
+
-----------------------------------------
1748
+
1749
+
**Default: `0` (disabled)**
1750
+
1751
+
Controls how permissive the `Stack<T>::get` operations are when reading values off the Lua stack.
1752
+
1753
+
| Type | Non-strict (default) | Strict |
1754
+
|------|---------------------|--------|
1755
+
|`bool`| Any Lua value is accepted via `lua_toboolean` (legacy behavior) | Only `LUA_TBOOLEAN` is accepted |
1756
+
| Integers | Any `LUA_TNUMBER` that fits the target integer type is accepted | Any `LUA_TNUMBER` that fits the target integer type is accepted (same behavior) |
1757
+
|`std::string`|`LUA_TSTRING` and `LUA_TNUMBER` accepted (numbers coerced to strings) | Only `LUA_TSTRING` is accepted |
1758
+
1759
+
In non-strict mode (the default), `lua_toboolean` semantics apply to `bool`: every Lua value except `false` and `nil` is truthy. This preserves backward-compatible behavior for existing code bases.
1760
+
1761
+
Enable strict mode when you want explicit, type-safe conversions:
1762
+
1763
+
```cpp
1764
+
#defineLUABRIDGE_STRICT_STACK_CONVERSIONS 1
1765
+
#include <LuaBridge/LuaBridge.h>
1766
+
```
1767
+
1768
+
With strict mode enabled:
1769
+
1770
+
```cpp
1771
+
lua_pushinteger (L, 42);
1772
+
auto r = luabridge::Stack<bool>::get (L, -1); // error: not a boolean
1773
+
1774
+
lua_pushnil (L);
1775
+
auto r = luabridge::Stack<bool>::get (L, -1); // error: not a boolean
1776
+
1777
+
lua_pushstring (L, "hello");
1778
+
auto r = luabridge::Stack<bool>::get (L, -1); // error: not a boolean
1779
+
1780
+
lua_pushboolean (L, 1);
1781
+
auto r = luabridge::Stack<bool>::get (L, -1); // ok: true
1782
+
```
1783
+
1784
+
6.3 - LUABRIDGE_SAFE_LUA_C_EXCEPTION_HANDLING
1785
+
-----------------------------------------------
1786
+
1787
+
**Default: `0` (disabled). Only meaningful when `LUABRIDGE_HAS_EXCEPTIONS` is `1`.**
1788
+
1789
+
When Lua is compiled as C and a C++ exception escapes a registered `lua_CFunction`, the Lua runtime will call `longjmp` instead of propagating the exception, which leads to undefined behavior. Enabling this flag adds a safe indirection that catches C++ exceptions at the CFunction boundary and re-raises them as Lua errors.
1790
+
1791
+
Enable this flag only if you are compiling Lua as C (not as C++), have exceptions enabled in your application, and you observe crashes when registered CFunctions throw:
1792
+
1793
+
```cpp
1794
+
#defineLUABRIDGE_SAFE_LUA_C_EXCEPTION_HANDLING 1
1795
+
#include <LuaBridge/LuaBridge.h>
1796
+
```
1797
+
1798
+
> **Warning:** Enabling this flag introduces a small performance overhead on every registered CFunction call through the library.
1799
+
1800
+
6.4 - LUABRIDGE_RAISE_UNREGISTERED_CLASS_USAGE
1801
+
------------------------------------------------
1802
+
1803
+
**Default: `1` when exceptions are enabled, `0` otherwise.**
1804
+
1805
+
When enabled, using an unregistered class with LuaBridge (for example, passing an instance of a type that has not been registered via `beginClass`) will raise an error rather than silently failing. With exceptions enabled this translates to a `luabridge::LuaException`; with exceptions disabled it translates to a Lua error via `lua_error`.
1806
+
1807
+
Override the default when you need fine-grained control:
0 commit comments