aboutsummaryrefslogtreecommitdiff
path: root/src/compat.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/compat.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/compat.cpp b/src/compat.cpp
index 591e19f..6ceed8f 100644
--- a/src/compat.cpp
+++ b/src/compat.cpp
@@ -6,6 +6,23 @@
6#include "macros_and_utils.h" 6#include "macros_and_utils.h"
7 7
8// ################################################################################################# 8// #################################################################################################
9
10// a small helper to obtain the "package" module table from the registry instead of relying on the presence of _G.package
11int luaG_getpackage(lua_State* L_)
12{
13 STACK_CHECK_START_REL(L_, 0);
14 int type{ lua503_getfield(L_, LUA_REGISTRYINDEX, LUA_LOADED_TABLE) }; // L_: _R._LOADED|nil
15 if (type != LUA_TTABLE) { // L_: _R._LOADED|nil
16 STACK_CHECK(L_, 1);
17 return type;
18 }
19 type = lua503_getfield(L_, -1, LUA_LOADLIBNAME); // L_: _R._LOADED package|nil
20 lua_remove(L_, -2); // L_: package|nil
21 STACK_CHECK(L_, 1);
22 return type;
23}
24
25// #################################################################################################
9// ################################################################################################# 26// #################################################################################################
10#if LUA_VERSION_NUM == 501 27#if LUA_VERSION_NUM == 501
11// ################################################################################################# 28// #################################################################################################
@@ -71,7 +88,7 @@ int lua_getiuservalue(lua_State* L_, int idx_, int n_)
71 88
72#if LUA_VERSION_NUM == 501 89#if LUA_VERSION_NUM == 501
73 /* default environment is not a nil (see lua_getfenv) */ 90 /* default environment is not a nil (see lua_getfenv) */
74 lua_getglobal(L_, "package"); 91 lua_getglobal(L_, LUA_LOADLIBNAME);
75 if (lua_rawequal(L_, -2, -1) || lua_rawequal(L_, -2, LUA_GLOBALSINDEX)) { 92 if (lua_rawequal(L_, -2, -1) || lua_rawequal(L_, -2, LUA_GLOBALSINDEX)) {
76 lua_pop(L_, 2); 93 lua_pop(L_, 2);
77 lua_pushnil(L_); 94 lua_pushnil(L_);