aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormpeterv <mpeterval@gmail.com>2015-02-25 10:00:47 +0300
committermpeterv <mpeterval@gmail.com>2015-02-25 10:00:47 +0300
commit20f0aed5462bd2dff3dde6abd52ae70728ae9d7a (patch)
treeb078d78eb43d1467beef08e5000b89406c6762c8
parentbe58bb0bf683c5c15589ecf68367a1fbaa9e0a8f (diff)
downloadlanes-20f0aed5462bd2dff3dde6abd52ae70728ae9d7a.tar.gz
lanes-20f0aed5462bd2dff3dde6abd52ae70728ae9d7a.tar.bz2
lanes-20f0aed5462bd2dff3dde6abd52ae70728ae9d7a.zip
Apply _ENV-related logic to Lua 5.3
It was only applied to Lua 5.2.
-rw-r--r--src/tools.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/tools.c b/src/tools.c
index bd1ea85..77f6abe 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -1256,13 +1256,13 @@ static void inter_copy_func( struct s_Universe* U, lua_State* L2, uint_t L2_cach
1256 1256
1257 /* push over any upvalues; references to this function will come from 1257 /* push over any upvalues; references to this function will come from
1258 * cache so we don't end up in eternal loop. 1258 * cache so we don't end up in eternal loop.
1259 * Lua5.2: one of the upvalues is _ENV, which we don't want to copy! 1259 * Lua5.2 and Lua5.3: one of the upvalues is _ENV, which we don't want to copy!
1260 * instead, the function shall have LUA_RIDX_GLOBALS taken in the destination state! 1260 * instead, the function shall have LUA_RIDX_GLOBALS taken in the destination state!
1261 */ 1261 */
1262 { 1262 {
1263 char const* upname; 1263 char const* upname;
1264#if LUA_VERSION_NUM == 502 1264#if LUA_VERSION_NUM >= 502
1265 // With Lua 5.2, each Lua function gets its environment as one of its upvalues (named LUA_ENV, aka "_ENV" by default) 1265 // Starting with Lua 5.2, each Lua function gets its environment as one of its upvalues (named LUA_ENV, aka "_ENV" by default)
1266 // Generally this is LUA_RIDX_GLOBALS, which we don't want to copy from the source to the destination state... 1266 // Generally this is LUA_RIDX_GLOBALS, which we don't want to copy from the source to the destination state...
1267 // -> if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table 1267 // -> if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table
1268 lua_pushglobaltable( L); // ... _G 1268 lua_pushglobaltable( L); // ... _G
@@ -1270,7 +1270,7 @@ static void inter_copy_func( struct s_Universe* U, lua_State* L2, uint_t L2_cach
1270 for( n = 0; (upname = lua_getupvalue( L, i, 1 + n)) != NULL; ++ n) 1270 for( n = 0; (upname = lua_getupvalue( L, i, 1 + n)) != NULL; ++ n)
1271 { // ... _G up[n] 1271 { // ... _G up[n]
1272 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "UPNAME[%d]: %s -> " INDENT_END, n, upname)); 1272 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "UPNAME[%d]: %s -> " INDENT_END, n, upname));
1273#if LUA_VERSION_NUM == 502 1273#if LUA_VERSION_NUM >= 502
1274 if( lua_rawequal( L, -1, -2)) // is the upvalue equal to the global table? 1274 if( lua_rawequal( L, -1, -2)) // is the upvalue equal to the global table?
1275 { 1275 {
1276 DEBUGSPEW_CODE( fprintf( stderr, "pushing destination global scope\n")); 1276 DEBUGSPEW_CODE( fprintf( stderr, "pushing destination global scope\n"));
@@ -1287,7 +1287,7 @@ static void inter_copy_func( struct s_Universe* U, lua_State* L2, uint_t L2_cach
1287 } 1287 }
1288 lua_pop( L, 1); // ... _G 1288 lua_pop( L, 1); // ... _G
1289 } 1289 }
1290#if LUA_VERSION_NUM == 502 1290#if LUA_VERSION_NUM >= 502
1291 lua_pop( L, 1); // ... 1291 lua_pop( L, 1); // ...
1292#endif // LUA_VERSION_NUM 1292#endif // LUA_VERSION_NUM
1293 } 1293 }