diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2021-06-16 14:16:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 14:16:20 +0200 |
commit | 21b2ac762ff8a5926872963aa2fd8feeb1bf3b39 (patch) | |
tree | 8a2b1414386a77c8cefe1e376b57baef613c7e69 | |
parent | e3cabe58aa63ef648e04dde1b634b3654d0df9ae (diff) | |
parent | a9daf44c335351366b96f2971b2f8acc227430b1 (diff) | |
download | lanes-21b2ac762ff8a5926872963aa2fd8feeb1bf3b39.tar.gz lanes-21b2ac762ff8a5926872963aa2fd8feeb1bf3b39.tar.bz2 lanes-21b2ac762ff8a5926872963aa2fd8feeb1bf3b39.zip |
Merge pull request #190 from eligovision/lanes_lua51_bugfix
Bug fix for Lua 5.1/LuaJIT: lua_getiuservalue must check if lua_getfe…
-rw-r--r-- | src/compat.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/compat.c b/src/compat.c index 9f36090..d9bc3dd 100644 --- a/src/compat.c +++ b/src/compat.c | |||
@@ -59,16 +59,35 @@ int lua_getiuservalue( lua_State* L, int idx, int n) | |||
59 | return LUA_TNONE; | 59 | return LUA_TNONE; |
60 | } | 60 | } |
61 | lua_getuservalue( L, idx); | 61 | lua_getuservalue( L, idx); |
62 | |||
63 | #if LUA_VERSION_NUM == 501 | ||
64 | /* default environment is not a nil (see lua_getfenv) */ | ||
65 | lua_getglobal(L, "package"); | ||
66 | if (lua_rawequal(L, -2, -1) || lua_rawequal(L, -2, LUA_GLOBALSINDEX)) | ||
67 | { | ||
68 | lua_pop(L, 2); | ||
69 | lua_pushnil( L); | ||
70 | |||
71 | return LUA_TNONE; | ||
72 | } | ||
73 | lua_pop(L, 1); /* remove package */ | ||
74 | #endif | ||
75 | |||
62 | return lua_type( L, -1); | 76 | return lua_type( L, -1); |
63 | } | 77 | } |
64 | 78 | ||
65 | int lua_setiuservalue( lua_State* L, int idx, int n) | 79 | int lua_setiuservalue( lua_State* L, int idx, int n) |
66 | { | 80 | { |
67 | if( n > 1) | 81 | if( n > 1 |
82 | #if LUA_VERSION_NUM == 501 | ||
83 | || lua_type( L, -1) != LUA_TTABLE | ||
84 | #endif | ||
85 | ) | ||
68 | { | 86 | { |
69 | lua_pop( L, 1); | 87 | lua_pop( L, 1); |
70 | return 0; | 88 | return 0; |
71 | } | 89 | } |
90 | |||
72 | (void) lua_setuservalue( L, idx); | 91 | (void) lua_setuservalue( L, idx); |
73 | return 1; // I guess anything non-0 is ok | 92 | return 1; // I guess anything non-0 is ok |
74 | } | 93 | } |