diff options
-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 | } |