aboutsummaryrefslogtreecommitdiff
path: root/ldblib.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldblib.c')
-rw-r--r--ldblib.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/ldblib.c b/ldblib.c
index 94087679..98b3106b 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.74 2002/12/04 17:38:31 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.75 2002/12/05 17:50:10 roberto Exp roberto $
3** Interface from Lua to its debug API 3** Interface from Lua to its debug API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -108,6 +108,30 @@ static int setlocal (lua_State *L) {
108} 108}
109 109
110 110
111static int auxupvalue (lua_State *L, int get) {
112 const char *name;
113 int n = luaL_checkint(L, 2);
114 luaL_checktype(L, 1, LUA_TFUNCTION);
115 if (lua_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from Lua */
116 name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
117 if (name == NULL) return 0;
118 lua_pushstring(L, name);
119 lua_insert(L, -(get+1));
120 return get + 1;
121}
122
123
124static int getupvalue (lua_State *L) {
125 return auxupvalue(L, 1);
126}
127
128
129static int setupvalue (lua_State *L) {
130 luaL_checkany(L, 3);
131 return auxupvalue(L, 0);
132}
133
134
111 135
112static const char KEY_HOOK = 'h'; 136static const char KEY_HOOK = 'h';
113 137
@@ -253,8 +277,10 @@ static const luaL_reg dblib[] = {
253 {"getlocal", getlocal}, 277 {"getlocal", getlocal},
254 {"getinfo", getinfo}, 278 {"getinfo", getinfo},
255 {"gethook", gethook}, 279 {"gethook", gethook},
280 {"getupvalue", getupvalue},
256 {"sethook", sethook}, 281 {"sethook", sethook},
257 {"setlocal", setlocal}, 282 {"setlocal", setlocal},
283 {"setupvalue", setupvalue},
258 {"debug", debug}, 284 {"debug", debug},
259 {"traceback", errorfb}, 285 {"traceback", errorfb},
260 {NULL, NULL} 286 {NULL, NULL}