api functions to manipulate upvalues do not need to check their

arguments (the caller must check them before calling)
This commit is contained in:
Roberto Ierusalimschy
2009-11-05 15:26:00 -02:00
parent 5598b2bc55
commit b7d5f18d71
3 changed files with 24 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.112 2009/09/09 20:32:19 roberto Exp roberto $
** $Id: ldblib.c,v 1.113 2009/11/05 16:48:31 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -199,23 +199,10 @@ static int db_setupvalue (lua_State *L) {
}
static int db_upvaladdr (lua_State *L) {
void *addr;
int n = luaL_checkint(L, 2);
luaL_checktype(L, 1, LUA_TFUNCTION);
addr = lua_upvaladdr(L, 1, n);
if (addr == NULL) lua_pushnil(L);
else lua_pushlightuserdata(L, addr);
return 1;
}
static int checkupval (lua_State *L, int argf, int argnup) {
lua_Debug ar;
int nup = luaL_checkint(L, argnup);
luaL_checktype(L, argf, LUA_TFUNCTION);
luaL_argcheck(L, !lua_iscfunction(L, argf), argf,
"cannot join upvalues of a C function");
lua_pushvalue(L, argf);
lua_getinfo(L, ">u", &ar);
luaL_argcheck(L, 1 <= nup && nup <= ar.nups, argnup, "invalid upvalue index");
@@ -223,9 +210,18 @@ static int checkupval (lua_State *L, int argf, int argnup) {
}
static int db_upvaladdr (lua_State *L) {
int n = checkupval(L, 1, 2);
lua_pushlightuserdata(L, lua_upvaladdr(L, 1, n));
return 1;
}
static int db_joinupval (lua_State *L) {
int n1 = checkupval(L, 1, 2);
int n2 = checkupval(L, 3, 4);
luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected");
luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected");
lua_upvaljoin(L, 1, n1, 3, n2);
return 0;
}