diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-03-19 12:02:34 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-03-19 12:02:34 -0300 |
commit | 5ca7cdd709e72766c2bfd145815bcb9f0dbaed63 (patch) | |
tree | dd01eddf6fbcf41c16fa8fe360e0608d298bc260 /loadlib.c | |
parent | 1514e49d4321efc30d597e05a072266c7c4d697d (diff) | |
download | lua-5ca7cdd709e72766c2bfd145815bcb9f0dbaed63.tar.gz lua-5ca7cdd709e72766c2bfd145815bcb9f0dbaed63.tar.bz2 lua-5ca7cdd709e72766c2bfd145815bcb9f0dbaed63.zip |
for compatibility only: 'module' changes the first upvalue of
calling function to affect its environment
Diffstat (limited to 'loadlib.c')
-rw-r--r-- | loadlib.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loadlib.c,v 1.80 2010/01/13 16:30:27 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.81 2010/03/17 21:37:37 roberto Exp roberto $ |
3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | ** | 5 | ** |
@@ -577,14 +577,18 @@ static int ll_require (lua_State *L) { | |||
577 | */ | 577 | */ |
578 | 578 | ||
579 | 579 | ||
580 | static void setfenv (lua_State *L) { | 580 | /* |
581 | ** FOR COMPATIBILITY ONLY: changes the _ENV variable of | ||
582 | ** calling function | ||
583 | */ | ||
584 | static void set_env (lua_State *L) { | ||
581 | lua_Debug ar; | 585 | lua_Debug ar; |
582 | if (lua_getstack(L, 1, &ar) == 0 || | 586 | if (lua_getstack(L, 1, &ar) == 0 || |
583 | lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ | 587 | lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ |
584 | lua_iscfunction(L, -1)) | 588 | lua_iscfunction(L, -1)) |
585 | luaL_error(L, LUA_QL("module") " not called from a Lua function"); | 589 | luaL_error(L, LUA_QL("module") " not called from a Lua function"); |
586 | lua_pushvalue(L, -2); /* copy new environment table to top */ | 590 | lua_pushvalue(L, -2); /* copy new environment table to top */ |
587 | lua_setfenv(L, -2); | 591 | lua_setupvalue(L, -2, 1); |
588 | lua_pop(L, 1); /* remove function */ | 592 | lua_pop(L, 1); /* remove function */ |
589 | } | 593 | } |
590 | 594 | ||
@@ -637,7 +641,7 @@ static int ll_module (lua_State *L) { | |||
637 | modinit(L, modname); | 641 | modinit(L, modname); |
638 | } | 642 | } |
639 | lua_pushvalue(L, -1); | 643 | lua_pushvalue(L, -1); |
640 | setfenv(L); | 644 | set_env(L); |
641 | dooptions(L, loaded - 1); | 645 | dooptions(L, loaded - 1); |
642 | return 1; | 646 | return 1; |
643 | } | 647 | } |