commit 692209fa8d2f9cb05d5b21860df4fd4eeb9622c4
parent 953d499ea25b95560dc53e97bcbdc2dab40d1dbf
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 11 Jan 2010 15:06:07 -0200
Dynamic C functions should be created with the global table as their
initial environments
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/loadlib.c b/loadlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: loadlib.c,v 1.73 2010/01/06 14:35:17 roberto Exp roberto $
+** $Id: loadlib.c,v 1.74 2010/01/11 16:10:47 roberto Exp roberto $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
@@ -344,7 +344,9 @@ static int ll_loadfunc (lua_State *L, const char *path, const char *sym) {
lua_CFunction f = ll_sym(L, *reg, sym);
if (f == NULL)
return ERRFUNC; /* unable to find function */
- lua_pushcfunction(L, f); /* else return function */
+ lua_pushcfunction(L, f); /* else create new function... */
+ lua_pushglobaltable(L); /* ... and set the standard global table... */
+ lua_setfenv(L, -2); /* ... as its environment */
return 0; /* no errors */
}
}