Skip to content

Commit 314c566

Browse files
authored
Add Lua 5.5 compatibility stopgap patch (#7404)
1 parent 5d9617f commit 314c566

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

cmake/FindLua.cmake

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ unset(_lua_append_versions)
4747

4848
# this is a function only to have all the variables inside go away automatically
4949
function(_lua_set_version_vars)
50-
set(LUA_VERSIONS5 5.4 5.3 5.2 5.1 5.0)
50+
set(LUA_VERSIONS5 5.5 5.4 5.3 5.2 5.1 5.0)
5151

5252
if (Lua_FIND_VERSION_EXACT)
5353
if (Lua_FIND_VERSION_COUNT GREATER 1)
@@ -102,22 +102,36 @@ function(_lua_check_header_version _hdr_file)
102102
# At least 5.[012] have different ways to express the version
103103
# so all of them need to be tested. Lua 5.2 defines LUA_VERSION
104104
# and LUA_RELEASE as joined by the C preprocessor, so avoid those.
105+
# Lua 5.5+ uses integer macros (LUA_VERSION_MAJOR_N) rather than
106+
# string literals for the version components.
105107
file(STRINGS "${_hdr_file}" lua_version_strings
106108
REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*")
107109

110+
# Lua 5.2–5.4: LUA_VERSION_MAJOR/MINOR/RELEASE are string literals ("5", "4", …)
108111
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings};")
109112
if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$")
110113
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};")
111114
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};")
112115
set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
113116
else ()
114-
string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
115-
if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$")
116-
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
117+
# Lua 5.5+: LUA_VERSION_MAJOR_N/MINOR_N/RELEASE_N are plain integers
118+
file(STRINGS "${_hdr_file}" lua_version_strings_n
119+
REGEX "^#define[ \t]+LUA_VERSION_(MAJOR|MINOR|RELEASE)_N[ \t]+[0-9]+")
120+
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR_N[ \t]+([0-9]+)[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings_n};")
121+
if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$")
122+
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR_N[ \t]+([0-9]+)[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings_n};")
123+
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE_N[ \t]+([0-9]+)[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings_n};")
124+
set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
125+
else ()
126+
# Lua 5.0–5.1: fall back to LUA_RELEASE / LUA_VERSION string literals
127+
string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
128+
if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$")
129+
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
130+
endif ()
131+
string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}")
132+
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}")
133+
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}")
117134
endif ()
118-
string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}")
119-
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}")
120-
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}")
121135
endif ()
122136
foreach (ver IN LISTS _lua_append_versions)
123137
if (ver STREQUAL "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")

third_party/sol2/include/sol/sol.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,7 +3535,7 @@ COMPAT53_API void luaL_requiref(lua_State *L, const char *modname,
35353535
#endif /* Lua 5.2 only */
35363536

35373537
/* other Lua versions */
3538-
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 || LUA_VERSION_NUM > 504
3538+
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 || LUA_VERSION_NUM > 505
35393539

35403540
# error "unsupported Lua version (i.e. not Lua 5.1, 5.2, 5.3, or 5.4)"
35413541

@@ -4419,7 +4419,7 @@ extern "C" {
44194419
}
44204420
#endif
44214421

4422-
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 504
4422+
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 504
44234423

44244424
#if !defined(LUA_ERRGCMM)
44254425
/* So Lua 5.4 actually removes this, which breaks sol2...
@@ -28250,6 +28250,13 @@ namespace sol {
2825028250

2825128251
namespace sol {
2825228252

28253+
inline lua_State* sol_lua_newstate(lua_Alloc f, void* ud, [[maybe_unused]] unsigned seed = 0) {
28254+
#if LUA_VERSION_NUM >= 505
28255+
return ::lua_newstate(f, ud, seed);
28256+
#else
28257+
return ::lua_newstate(f, ud);
28258+
#endif
28259+
}
2825328260
class state : private std::unique_ptr<lua_State, detail::state_deleter>, public state_view {
2825428261
private:
2825528262
typedef std::unique_ptr<lua_State, detail::state_deleter> unique_base;
@@ -28260,7 +28267,7 @@ namespace sol {
2826028267
}
2826128268

2826228269
state(lua_CFunction panic, lua_Alloc alfunc, void* alpointer = nullptr)
28263-
: unique_base(lua_newstate(alfunc, alpointer)), state_view(unique_base::get()) {
28270+
: unique_base(sol_lua_newstate(alfunc, alpointer)), state_view(unique_base::get()) {
2826428271
set_default_state(unique_base::get(), panic);
2826528272
}
2826628273

0 commit comments

Comments
 (0)