Browse Source

'loadin' should accept any value for the environment (not only tables) +
it should check whether chunk has upvalue named '_ENV'

Roberto Ierusalimschy 15 years ago
parent
commit
daa5fe3e31
1 changed files with 6 additions and 3 deletions
  1. 6 3
      lbaselib.c

+ 6 - 3
lbaselib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lbaselib.c,v 1.245 2010/06/13 19:41:34 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.246 2010/07/02 11:38:13 roberto Exp roberto $
 ** Basic library
 ** See Copyright Notice in lua.h
 */
@@ -330,11 +330,14 @@ static int luaB_load (lua_State *L) {
 
 static int luaB_loadin (lua_State *L) {
   int n;
-  luaL_checktype(L, 1, LUA_TTABLE);
+  luaL_checkany(L, 1);
   n = luaB_load_aux(L, 2);
   if (n == 1) {  /* success? */
+    const char *name;
     lua_pushvalue(L, 1);  /* environment for loaded function */
-    lua_setupvalue(L, -2, 1);
+    name = lua_setupvalue(L, -2, 1);
+    if (name == NULL || strcmp(name, "_ENV") != 0)
+      luaL_error(L, "loaded chunk does not have environment upvalue");
   }
   return n;
 }