aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compat.c21
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
65int lua_setiuservalue( lua_State* L, int idx, int n) 79int 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}