Skip to content

Commit 1a76c41

Browse files
committed
enforce lua version compatibility
1 parent eb1d7c9 commit 1a76c41

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ if (WithSharedLibluv)
7171
find_package(Libuv REQUIRED)
7272
include_directories(${LIBUV_INCLUDE_DIRS})
7373

74+
include(CheckCSourceCompiles)
75+
76+
set(CMAKE_REQUIRED_INCLUDES ${LUAJIT_INCLUDE_DIRS})
77+
set(CMAKE_REQUIRED_LIBRARIES ${LUAJIT_LIBRARIES})
78+
check_c_source_compiles("
79+
#include <luajit.h>
80+
int main() {
81+
LUAJIT_VERSION_SYM();
82+
return 0;
83+
}" LUAJIT_HAS_VERSION_SYM)
84+
if (NOT LUAJIT_HAS_VERSION_SYM)
85+
add_compile_definitions(LUAJIT_MISSING_VERSION_SYM)
86+
endif ()
87+
7488
list(APPEND LUVI_LIBRARIES ${LUV_LIBRARIES} ${LUAJIT_LIBRARIES} ${LIBUV_LIBRARIES})
7589
else (WithSharedLibluv)
7690
# Build luv as static library instead of as module

src/luvi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "lauxlib.h"
2323
#include "uv.h"
2424
#include "luv.h"
25+
#ifndef WITH_PLAIN_LUA
26+
#include "luajit.h"
27+
#endif
2528

2629
#include <string.h>
2730
#include <stdlib.h>

src/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ static lua_State* vm_acquire(){
5555
if (L == NULL)
5656
return L;
5757

58+
// Ensure that the version of lua interpreter is compatible with the version luvi was compiled with.
59+
#ifdef WITH_PLAIN_LUA
60+
#if (LUA_VERSION_NUM >= 502)
61+
luaL_checkversion(L);
62+
#endif
63+
#else
64+
#ifndef LUAJIT_MISSING_VERSION_SYM // debian patches luajit to remove this symbol, so we can't check it.
65+
LUAJIT_VERSION_SYM();
66+
#endif
67+
#endif
68+
5869
// Add in the lua standard and compat libraries
5970
luvi_openlibs(L);
6071

0 commit comments

Comments
 (0)