Skip to content

Commit

Permalink
Merge pull request #298 from truemedian/version-compat
Browse files Browse the repository at this point in the history
enforce lua version compatibility
  • Loading branch information
SinisterRectus authored Oct 8, 2024
2 parents eb1d7c9 + 1a76c41 commit 32b274b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ if (WithSharedLibluv)
find_package(Libuv REQUIRED)
include_directories(${LIBUV_INCLUDE_DIRS})

include(CheckCSourceCompiles)

set(CMAKE_REQUIRED_INCLUDES ${LUAJIT_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${LUAJIT_LIBRARIES})
check_c_source_compiles("
#include <luajit.h>
int main() {
LUAJIT_VERSION_SYM();
return 0;
}" LUAJIT_HAS_VERSION_SYM)
if (NOT LUAJIT_HAS_VERSION_SYM)
add_compile_definitions(LUAJIT_MISSING_VERSION_SYM)
endif ()

list(APPEND LUVI_LIBRARIES ${LUV_LIBRARIES} ${LUAJIT_LIBRARIES} ${LIBUV_LIBRARIES})
else (WithSharedLibluv)
# Build luv as static library instead of as module
Expand Down
3 changes: 3 additions & 0 deletions src/luvi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "lauxlib.h"
#include "uv.h"
#include "luv.h"
#ifndef WITH_PLAIN_LUA
#include "luajit.h"
#endif

#include <string.h>
#include <stdlib.h>
Expand Down
11 changes: 11 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ static lua_State* vm_acquire(){
if (L == NULL)
return L;

// Ensure that the version of lua interpreter is compatible with the version luvi was compiled with.
#ifdef WITH_PLAIN_LUA
#if (LUA_VERSION_NUM >= 502)
luaL_checkversion(L);
#endif
#else
#ifndef LUAJIT_MISSING_VERSION_SYM // debian patches luajit to remove this symbol, so we can't check it.
LUAJIT_VERSION_SYM();
#endif
#endif

// Add in the lua standard and compat libraries
luvi_openlibs(L);

Expand Down

0 comments on commit 32b274b

Please sign in to comment.