Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce lua version compatibility #298

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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