From dd8edecae19251a3b89502416a2e7f8e75b2bd20 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 19 Dec 2002 09:11:55 -0200 Subject: new functions to manipulate upvales (get/setupvalue) --- ltests.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'ltests.c') diff --git a/ltests.c b/ltests.c index adc1d260..a326c2de 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 1.147 2002/12/04 17:29:05 roberto Exp roberto $ +** $Id: ltests.c,v 1.148 2002/12/04 17:38:31 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -384,6 +384,24 @@ static int metatable (lua_State *L) { return 1; } + +static int upvalue (lua_State *L) { + int n = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TFUNCTION); + if (lua_isnone(L, 3)) { + const char *name = lua_getupvalue(L, 1, n); + if (name == NULL) return 0; + lua_pushstring(L, name); + return 2; + } + else { + const char *name = lua_setupvalue(L, 1, n); + lua_pushstring(L, name); + return 1; + } +} + + static int newuserdata (lua_State *L) { size_t size = luaL_checkint(L, 1); char *p = cast(char *, lua_newuserdata(L, size)); @@ -754,6 +772,7 @@ static const struct luaL_reg tests_funcs[] = { {"d2s", d2s}, {"s2d", s2d}, {"metatable", metatable}, + {"upvalue", upvalue}, {"newuserdata", newuserdata}, {"pushuserdata", pushuserdata}, {"udataval", udataval}, -- cgit v1.2.3-55-g6feb