aboutsummaryrefslogtreecommitdiff
path: root/loadlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-03-19 12:02:34 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-03-19 12:02:34 -0300
commit5ca7cdd709e72766c2bfd145815bcb9f0dbaed63 (patch)
treedd01eddf6fbcf41c16fa8fe360e0608d298bc260 /loadlib.c
parent1514e49d4321efc30d597e05a072266c7c4d697d (diff)
downloadlua-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.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/loadlib.c b/loadlib.c
index 44112e31..f8270d86 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -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
580static void setfenv (lua_State *L) { 580/*
581** FOR COMPATIBILITY ONLY: changes the _ENV variable of
582** calling function
583*/
584static 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}