aboutsummaryrefslogtreecommitdiff
path: root/ldblib.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldblib.c')
-rw-r--r--ldblib.c78
1 files changed, 45 insertions, 33 deletions
diff --git a/ldblib.c b/ldblib.c
index ac3ad11a..c3ca748e 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,10 +1,11 @@
1/* 1/*
2** $Id: ldblib.c,v 1.13 2000/04/14 17:44:20 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.14 2000/05/08 13:21:35 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*/
6 6
7 7
8#include <stdio.h>
8#include <stdlib.h> 9#include <stdlib.h>
9#include <string.h> 10#include <string.h>
10 11
@@ -41,40 +42,51 @@ static void settabso (lua_State *L, lua_Object t, const char *i, lua_Object v) {
41} 42}
42 43
43 44
44static void getstack (lua_State *L) { 45static void getinfo (lua_State *L) {
45 lua_Debug ar; 46 lua_Debug ar;
46 if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ 47 lua_Object res;
47 return; 48 lua_Object func = lua_getparam(L, 1);
48 else { 49 const char *options = luaL_opt_string(L, 2, "flnSu");
49 const char *options = luaL_opt_string(L, 2, "flnSu"); 50 char buff[20];
50 lua_Object res = lua_createtable(L); 51 if (lua_isnumber(L, func)) {
51 if (!lua_getinfo(L, options, &ar)) 52 if (!lua_getstack(L, lua_getnumber(L, func), &ar)) {
52 luaL_argerror(L, 2, "invalid option"); 53 lua_pushnil(L); /* level out of range */
53 for (; *options; options++) { 54 return;
54 switch (*options) { 55 }
55 case 'S': 56 }
56 settabss(L, res, "source", ar.source); 57 else if (lua_isfunction(L, func)) {
57 settabsi(L, res, "linedefined", ar.linedefined); 58 ar.func = func;
58 settabss(L, res, "what", ar.what); 59 sprintf(buff, ">%.10s", options);
59 break; 60 options = buff;
60 case 'l': 61 }
61 settabsi(L, res, "currentline", ar.currentline); 62 else
62 break; 63 luaL_argerror(L, 1, "function or level expected");
63 case 'u': 64 res = lua_createtable(L);
64 settabsi(L, res, "nups", ar.nups); 65 if (!lua_getinfo(L, options, &ar))
65 break; 66 luaL_argerror(L, 2, "invalid option");
66 case 'n': 67 for (; *options; options++) {
67 settabss(L, res, "name", ar.name); 68 switch (*options) {
68 settabss(L, res, "namewhat", ar.namewhat); 69 case 'S':
69 break; 70 settabss(L, res, "source", ar.source);
70 case 'f': 71 settabsi(L, res, "linedefined", ar.linedefined);
71 settabso(L, res, "func", ar.func); 72 settabss(L, res, "what", ar.what);
72 break; 73 break;
73 74 case 'l':
74 } 75 settabsi(L, res, "currentline", ar.currentline);
76 break;
77 case 'u':
78 settabsi(L, res, "nups", ar.nups);
79 break;
80 case 'n':
81 settabss(L, res, "name", ar.name);
82 settabss(L, res, "namewhat", ar.namewhat);
83 break;
84 case 'f':
85 settabso(L, res, "func", ar.func);
86 break;
75 } 87 }
76 lua_pushobject(L, res);
77 } 88 }
89 lua_pushobject(L, res);
78} 90}
79 91
80 92
@@ -163,7 +175,7 @@ static void setlinehook (lua_State *L) {
163 175
164static const struct luaL_reg dblib[] = { 176static const struct luaL_reg dblib[] = {
165 {"getlocal", getlocal}, 177 {"getlocal", getlocal},
166 {"getstack", getstack}, 178 {"getinfo", getinfo},
167 {"setcallhook", setcallhook}, 179 {"setcallhook", setcallhook},
168 {"setlinehook", setlinehook}, 180 {"setlinehook", setlinehook},
169 {"setlocal", setlocal} 181 {"setlocal", setlocal}