lua

A copy of the Lua development repository
Log | Files | Refs | README

commit daa5fe3e31d8ca28a8770df135cbad7fa6fdfa4b
parent 8d9ea59d28e0a4626ce8372f6f643c30d79063aa
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Mon, 23 Aug 2010 15:02:47 -0300

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

Diffstat:
Mlbaselib.c | 9++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lbaselib.c b/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; }