From b7d5f18d71f691df752e220f844ea613a8f6d722 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 5 Nov 2009 15:26:00 -0200 Subject: api functions to manipulate upvalues do not need to check their arguments (the caller must check them before calling) --- ldblib.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'ldblib.c') diff --git a/ldblib.c b/ldblib.c index e067efac..5c1c57d0 100644 --- a/ldblib.c +++ b/ldblib.c @@ -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; } -- cgit v1.2.3-55-g6feb