aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-02-22 16:23:02 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2024-02-22 16:23:02 +0100
commit7c439d1b6f6c6115f38605b2d51c44d7a6c08052 (patch)
tree9660423252eebc05cef8802e2310a2234a91225a /src
parentbb84407e9c0076222cc5a0bd1df0bdfdf7e55a57 (diff)
downloadlanes-7c439d1b6f6c6115f38605b2d51c44d7a6c08052.tar.gz
lanes-7c439d1b6f6c6115f38605b2d51c44d7a6c08052.tar.bz2
lanes-7c439d1b6f6c6115f38605b2d51c44d7a6c08052.zip
Detect runtime LuaJIT/PUC-Lua mismatch
Diffstat (limited to 'src')
-rw-r--r--src/lanes.c21
-rw-r--r--src/lanes.h2
2 files changed, 17 insertions, 6 deletions
diff --git a/src/lanes.c b/src/lanes.c
index d2c95ee..332a1b8 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -2083,6 +2083,17 @@ int LANES_API luaopen_lanes_core( lua_State* L)
2083 STACK_GROW( L, 4); 2083 STACK_GROW( L, 4);
2084 STACK_CHECK( L, 0); 2084 STACK_CHECK( L, 0);
2085 2085
2086 // Prevent PUC-Lua/LuaJIT mismatch. Hopefully this works for MoonJIT too
2087 lua_getglobal( L, "jit"); // {jit?}
2088#if LUAJIT_FLAVOR() == 0
2089 if (!lua_isnil( L, -1))
2090 return luaL_error( L, "Lanes is built for PUC-Lua, don't run from LuaJIT");
2091#else
2092 if (lua_isnil( L, -1))
2093 return luaL_error( L, "Lanes is built for LuaJIT, don't run from PUC-Lua");
2094#endif
2095 lua_pop( L, 1); //
2096
2086 // Create main module interface table 2097 // Create main module interface table
2087 // we only have 1 closure, which must be called to configure Lanes 2098 // we only have 1 closure, which must be called to configure Lanes
2088 lua_newtable( L); // M 2099 lua_newtable( L); // M
@@ -2092,15 +2103,15 @@ int LANES_API luaopen_lanes_core( lua_State* L)
2092 REGISTRY_GET( L, CONFIG_REGKEY); // M LG_configure() settings 2103 REGISTRY_GET( L, CONFIG_REGKEY); // M LG_configure() settings
2093 if( !lua_isnil( L, -1)) // this is not the first require "lanes.core": call configure() immediately 2104 if( !lua_isnil( L, -1)) // this is not the first require "lanes.core": call configure() immediately
2094 { 2105 {
2095 lua_pushvalue( L, -1); // M LG_configure() settings settings 2106 lua_pushvalue( L, -1); // M LG_configure() settings settings
2096 lua_setfield( L, -4, "settings"); // M LG_configure() settings 2107 lua_setfield( L, -4, "settings"); // M LG_configure() settings
2097 lua_call( L, 1, 0); // M 2108 lua_call( L, 1, 0); // M
2098 } 2109 }
2099 else 2110 else
2100 { 2111 {
2101 // will do nothing on first invocation, as we haven't stored settings in the registry yet 2112 // will do nothing on first invocation, as we haven't stored settings in the registry yet
2102 lua_setfield( L, -3, "settings"); // M LG_configure() 2113 lua_setfield( L, -3, "settings"); // M LG_configure()
2103 lua_setfield( L, -2, "configure"); // M 2114 lua_setfield( L, -2, "configure"); // M
2104 } 2115 }
2105 2116
2106 STACK_END( L, 1); 2117 STACK_END( L, 1);
diff --git a/src/lanes.h b/src/lanes.h
index b9245f3..7e1a2e5 100644
--- a/src/lanes.h
+++ b/src/lanes.h
@@ -12,7 +12,7 @@
12 12
13#define LANES_VERSION_MAJOR 3 13#define LANES_VERSION_MAJOR 3
14#define LANES_VERSION_MINOR 16 14#define LANES_VERSION_MINOR 16
15#define LANES_VERSION_PATCH 2 15#define LANES_VERSION_PATCH 3
16 16
17#define LANES_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>=PATCH)))) 17#define LANES_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>=PATCH))))
18#define LANES_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR<MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR<MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH<PATCH)))) 18#define LANES_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR<MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR<MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH<PATCH))))