aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-08-05 16:25:42 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-08-05 16:25:42 -0300
commitbb48f456d92077e431af489c87031373c916463a (patch)
treece0d322e336aa67b4c7831d6740041c6ccc0911d
parentdf802dc74b12f0cdee1df0ec119a21022a94545a (diff)
downloadlua-bb48f456d92077e431af489c87031373c916463a.tar.gz
lua-bb48f456d92077e431af489c87031373c916463a.tar.bz2
lua-bb48f456d92077e431af489c87031373c916463a.zip
bug: 'module' now checks that is caller is a Lua function
-rw-r--r--loadlib.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/loadlib.c b/loadlib.c
index c06c56f4..e6a51b7e 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.58 2007/06/21 13:52:27 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.59 2007/12/12 14:36:12 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**
@@ -521,11 +521,14 @@ static int ll_require (lua_State *L) {
521 521
522static void setfenv (lua_State *L) { 522static void setfenv (lua_State *L) {
523 lua_Debug ar; 523 lua_Debug ar;
524 lua_getstack(L, 1, &ar); 524 if (lua_getstack(L, 1, &ar) == 0 ||
525 lua_getinfo(L, "f", &ar); 525 lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
526 lua_pushvalue(L, -2); 526 lua_iscfunction(L, -1))
527 luaL_error(L, "function " LUA_QL("module")
528 " not called from a Lua function");
529 lua_pushvalue(L, -2); /* copy new environment table to top */
527 lua_setfenv(L, -2); 530 lua_setfenv(L, -2);
528 lua_pop(L, 1); 531 lua_pop(L, 1); /* remove function */
529} 532}
530 533
531 534