aboutsummaryrefslogtreecommitdiff
path: root/ldblib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-28 14:57:04 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-28 14:57:04 -0300
commit9fdf73bc9a6b4c6afbfff1d8181fface6b1c6761 (patch)
treeda8d97d954e5ffabf9ff275df725f1e0a3a5b3e6 /ldblib.c
parentf1fd9b5c2c21f24d25d7813f431a3495702ebea6 (diff)
downloadlua-9fdf73bc9a6b4c6afbfff1d8181fface6b1c6761.tar.gz
lua-9fdf73bc9a6b4c6afbfff1d8181fface6b1c6761.tar.bz2
lua-9fdf73bc9a6b4c6afbfff1d8181fface6b1c6761.zip
first version for new API
Diffstat (limited to 'ldblib.c')
-rw-r--r--ldblib.c104
1 files changed, 49 insertions, 55 deletions
diff --git a/ldblib.c b/ldblib.c
index 45edc8c2..17edcda5 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.17 2000/06/12 13:52:05 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.18 2000/08/09 19:16:57 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*/
@@ -17,102 +17,96 @@
17 17
18 18
19 19
20static void settabss (lua_State *L, lua_Object t, const char *i, const char *v) { 20static void settabss (lua_State *L, const char *i, const char *v) {
21 lua_pushobject(L, t); 21 lua_pushobject(L, -1);
22 lua_pushstring(L, i); 22 lua_pushstring(L, i);
23 lua_pushstring(L, v); 23 lua_pushstring(L, v);
24 lua_settable(L); 24 lua_settable(L);
25} 25}
26 26
27 27
28static void settabsi (lua_State *L, lua_Object t, const char *i, int v) { 28static void settabsi (lua_State *L, const char *i, int v) {
29 lua_pushobject(L, t); 29 lua_pushobject(L, -1);
30 lua_pushstring(L, i); 30 lua_pushstring(L, i);
31 lua_pushnumber(L, v); 31 lua_pushnumber(L, v);
32 lua_settable(L); 32 lua_settable(L);
33} 33}
34 34
35 35
36static void settabso (lua_State *L, lua_Object t, const char *i, lua_Object v) { 36static int getinfo (lua_State *L) {
37 lua_pushobject(L, t);
38 lua_pushstring(L, i);
39 lua_pushobject(L, v);
40 lua_settable(L);
41}
42
43
44static void getinfo (lua_State *L) {
45 lua_Debug ar; 37 lua_Debug ar;
46 lua_Object res;
47 lua_Object func = lua_getparam(L, 1);
48 const char *options = luaL_opt_string(L, 2, "flnSu"); 38 const char *options = luaL_opt_string(L, 2, "flnSu");
49 char buff[20]; 39 char buff[20];
50 if (lua_isnumber(L, func)) { 40 if (lua_isnumber(L, 1)) {
51 if (!lua_getstack(L, (int)lua_getnumber(L, func), &ar)) { 41 if (!lua_getstack(L, (int)lua_tonumber(L, 1), &ar)) {
52 lua_pushnil(L); /* level out of range */ 42 lua_pushnil(L); /* level out of range */
53 return; 43 return 1;
54 } 44 }
55 } 45 }
56 else if (lua_isfunction(L, func)) { 46 else if (lua_isfunction(L, 1)) {
57 ar.func = func; 47 lua_pushobject(L, 1);
58 sprintf(buff, ">%.10s", options); 48 sprintf(buff, ">%.10s", options);
59 options = buff; 49 options = buff;
60 } 50 }
61 else 51 else
62 luaL_argerror(L, 1, "function or level expected"); 52 luaL_argerror(L, 1, "function or level expected");
63 res = lua_createtable(L);
64 if (!lua_getinfo(L, options, &ar)) 53 if (!lua_getinfo(L, options, &ar))
65 luaL_argerror(L, 2, "invalid option"); 54 luaL_argerror(L, 2, "invalid option");
55 lua_newtable(L);
66 for (; *options; options++) { 56 for (; *options; options++) {
67 switch (*options) { 57 switch (*options) {
68 case 'S': 58 case 'S':
69 settabss(L, res, "source", ar.source); 59 settabss(L, "source", ar.source);
70 settabsi(L, res, "linedefined", ar.linedefined); 60 settabsi(L, "linedefined", ar.linedefined);
71 settabss(L, res, "what", ar.what); 61 settabss(L, "what", ar.what);
72 break; 62 break;
73 case 'l': 63 case 'l':
74 settabsi(L, res, "currentline", ar.currentline); 64 settabsi(L, "currentline", ar.currentline);
75 break; 65 break;
76 case 'u': 66 case 'u':
77 settabsi(L, res, "nups", ar.nups); 67 settabsi(L, "nups", ar.nups);
78 break; 68 break;
79 case 'n': 69 case 'n':
80 settabss(L, res, "name", ar.name); 70 settabss(L, "name", ar.name);
81 settabss(L, res, "namewhat", ar.namewhat); 71 settabss(L, "namewhat", ar.namewhat);
82 break; 72 break;
83 case 'f': 73 case 'f':
84 settabso(L, res, "func", ar.func); 74 lua_pushobject(L, -1);
75 lua_pushstring(L, "func");
76 lua_pushobject(L, -4);
77 lua_settable(L);
85 break; 78 break;
86 } 79 }
87 } 80 }
88 lua_pushobject(L, res); 81 return 1; /* return table */
89} 82}
90 83
91 84
92static void getlocal (lua_State *L) { 85static int getlocal (lua_State *L) {
93 lua_Debug ar; 86 lua_Debug ar;
94 lua_Localvar lvar; 87 const char *name;
95 if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ 88 if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */
96 luaL_argerror(L, 1, "level out of range"); 89 luaL_argerror(L, 1, "level out of range");
97 lvar.index = luaL_check_int(L, 2); 90 name = lua_getlocal(L, &ar, luaL_check_int(L, 2));
98 if (lua_getlocal(L, &ar, &lvar)) { 91 if (name) {
99 lua_pushstring(L, lvar.name); 92 lua_pushstring(L, name);
100 lua_pushobject(L, lvar.value); 93 lua_pushobject(L, -2);
94 return 2;
95 }
96 else {
97 lua_pushnil(L);
98 return 1;
101 } 99 }
102 else lua_pushnil(L);
103} 100}
104 101
105 102
106static void setlocal (lua_State *L) { 103static int setlocal (lua_State *L) {
107 lua_Debug ar; 104 lua_Debug ar;
108 lua_Localvar lvar;
109 if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ 105 if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */
110 luaL_argerror(L, 1, "level out of range"); 106 luaL_argerror(L, 1, "level out of range");
111 lvar.index = luaL_check_int(L, 2); 107 luaL_checktype(L, 3, "any");
112 lvar.value = luaL_nonnullarg(L, 3); 108 lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2)));
113 if (lua_setlocal(L, &ar, &lvar)) 109 return 1;
114 lua_pushstring(L, lvar.name);
115 else lua_pushnil(L);
116} 110}
117 111
118 112
@@ -128,47 +122,47 @@ static int callhook = LUA_NOREF; /* Lua reference to call hook function */
128 122
129static void linef (lua_State *L, lua_Debug *ar) { 123static void linef (lua_State *L, lua_Debug *ar) {
130 if (linehook != LUA_NOREF) { 124 if (linehook != LUA_NOREF) {
125 lua_getref(L, linehook);
131 lua_pushnumber(L, ar->currentline); 126 lua_pushnumber(L, ar->currentline);
132 lua_callfunction(L, lua_getref(L, linehook)); 127 lua_call(L, 1, 0);
133 } 128 }
134} 129}
135 130
136 131
137static void callf (lua_State *L, lua_Debug *ar) { 132static void callf (lua_State *L, lua_Debug *ar) {
138 if (callhook != LUA_NOREF) { 133 if (callhook != LUA_NOREF) {
134 lua_getref(L, callhook);
139 lua_pushstring(L, ar->event); 135 lua_pushstring(L, ar->event);
140 lua_callfunction(L, lua_getref(L, callhook)); 136 lua_call(L, 1, 0);
141 } 137 }
142} 138}
143 139
144 140
145static void setcallhook (lua_State *L) { 141static int setcallhook (lua_State *L) {
146 lua_Object f = lua_getparam(L, 1);
147 lua_unref(L, callhook); 142 lua_unref(L, callhook);
148 if (f == LUA_NOOBJECT) { 143 if (lua_isnull(L, 1)) {
149 callhook = LUA_NOREF; 144 callhook = LUA_NOREF;
150 lua_setcallhook(L, NULL); 145 lua_setcallhook(L, NULL);
151 } 146 }
152 else { 147 else {
153 lua_pushobject(L, f);
154 callhook = lua_ref(L, 1); 148 callhook = lua_ref(L, 1);
155 lua_setcallhook(L, callf); 149 lua_setcallhook(L, callf);
156 } 150 }
151 return 0;
157} 152}
158 153
159 154
160static void setlinehook (lua_State *L) { 155static int setlinehook (lua_State *L) {
161 lua_Object f = lua_getparam(L, 1);
162 lua_unref(L, linehook); 156 lua_unref(L, linehook);
163 if (f == LUA_NOOBJECT) { 157 if (lua_isnull(L, 1)) {
164 linehook = LUA_NOREF; 158 linehook = LUA_NOREF;
165 lua_setlinehook(L, NULL); 159 lua_setlinehook(L, NULL);
166 } 160 }
167 else { 161 else {
168 lua_pushobject(L, f);
169 linehook = lua_ref(L, 1); 162 linehook = lua_ref(L, 1);
170 lua_setlinehook(L, linef); 163 lua_setlinehook(L, linef);
171 } 164 }
165 return 0;
172} 166}
173 167
174 168