Keep math.mod and string.gfind when LuaJIT 2.1 is used

Code written assuming LuaJIT 2.0 is being used might rely on them, even though they're deprecated (and removed in LuaJIT 2.1).
This commit is contained in:
Alex Szpakowski
2020-12-23 12:58:26 -04:00
parent bfaae71f2a
commit f3afdee70a
+24
View File
@@ -362,6 +362,23 @@ static int w_deprecation__gc(lua_State *)
return 0;
}
static void luax_addcompatibilityalias(lua_State *L, const char *module, const char *name, const char *alias)
{
lua_getglobal(L, module);
if (lua_istable(L, -1))
{
lua_getfield(L, -1, alias);
bool hasalias = !lua_isnoneornil(L, -1);
lua_pop(L, 1);
if (!hasalias)
{
lua_getfield(L, -1, name);
lua_setfield(L, -2, alias);
}
}
lua_pop(L, 1);
}
int luaopen_love(lua_State *L)
{
love::luax_insistpinnedthread(L);
@@ -469,6 +486,13 @@ int luaopen_love(lua_State *L)
love::luax_require(L, "love.data");
lua_pop(L, 1);
#if LUA_VERSION_NUM <= 501
// These are deprecated in Lua 5.1. LuaJIT 2.1 removes them, but code
// written assuming LuaJIT 2.0 or Lua 5.1 is used might still rely on them.
luax_addcompatibilityalias(L, "math", "fmod", "mod");
luax_addcompatibilityalias(L, "string", "gmatch", "gfind");
#endif
#ifdef LOVE_ENABLE_LUASOCKET
love::luasocket::__open(L);
#endif