Closed cuavas closed 1 year ago
Bump, I can reproduce this and can confirm that the proposed fix solves the issue. It seems to be just a typo to compare against 0 instead of the proper defined
This is not a typo, it's intentional. There should be a value in there, and it should be an integer -- any integer at all, indicating if it's on or off.
This is not a typo, it's intentional. There should be a value in there, and it should be an integer -- any integer at all, indicating if it's on or off.
That’s not correct though. If you look at the Lua source, it does not check for “a value in there”, it simply checks whether the macro is defined or not. #define LUA_COMPAT_BITLIB
has the same effect as #define LUA_COMPAT_BITLIB 0
or #define LUA_COMPAT_BITLIB 1
. When you define LUA_COMPAT_5_2
, Lua itself defines LUA_COMPAT_BITLIB
as an empty macro, enabling the feature.
You’re assuming Lua uses the same semantics for its feature macros that you use for yours. This assumption is incorrect.
The issue is an apparent misinterpretation of how Lua compatibility macros are defined.
Consider this fragment from Lua’s src/luaconf.h (starts at line 303 in Lua 5.3.4):
Note that if Lua 5.2 compatibility is enabled,
LUA_COMPAT_BITLIB
will be defined as an empty macro.Now consider this code in sol2’s include/sol/compatibility/lua_version.hpp (beginning at line 186 in sol2 v3.3.0): https://github.com/ThePhD/sol2/blob/v3.3.0/include/sol/compatibility/lua_version.hpp#L186
On line 195, this fragment causes a compilation error with clang and GCC:
(defined(LUA_COMPAT_BITLIB) && (LUA_COMPAT_BITLIB != 0))
Because
LUA_COMPAT_BITLIB
is defined as an empty macro, it’s substituted as(1 && ( != 0))
so the compilers produce an error because there’s no left-hand argument to the not-equal operator (!=
).The
LUA_COMPAT_*
macros should only be tested for being defined or undefined. The Lua headers define them as empty macros when enabled, so attempting to compare them to 1/0 causes compilation errors.I can open a PR to change line 195 to this if it would be considered a good solution: