@@ -47,7 +47,7 @@ unset(_lua_append_versions)
4747
4848# this is a function only to have all the variables inside go away automatically
4949function (_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} " )
0 commit comments