aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-20 14:39:03 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-20 14:39:03 -0200
commit64eecc0b8219cc3bcaa2b717826a4376c60d9305 (patch)
treea1633501cdf21016a00bd555c475daea58ec24f5 /ldebug.c
parent8b88ab07f7cfc216407a88d75ad8f0546224c8d7 (diff)
downloadlua-64eecc0b8219cc3bcaa2b717826a4376c60d9305.tar.gz
lua-64eecc0b8219cc3bcaa2b717826a4376c60d9305.tar.bz2
lua-64eecc0b8219cc3bcaa2b717826a4376c60d9305.zip
new macro LUA_API
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/ldebug.c b/ldebug.c
index 04e81ac4..fa38f132 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.46 2000/10/06 12:45:25 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.47 2000/10/09 13:47:32 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -41,14 +41,14 @@ static int isLmark (StkId o) {
41} 41}
42 42
43 43
44lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) { 44LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) {
45 lua_Hook oldhook = L->callhook; 45 lua_Hook oldhook = L->callhook;
46 L->callhook = func; 46 L->callhook = func;
47 return oldhook; 47 return oldhook;
48} 48}
49 49
50 50
51lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { 51LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) {
52 lua_Hook oldhook = L->linehook; 52 lua_Hook oldhook = L->linehook;
53 L->linehook = func; 53 L->linehook = func;
54 return oldhook; 54 return oldhook;
@@ -68,7 +68,7 @@ static StkId aux_stackedfunction (lua_State *L, int level, StkId top) {
68} 68}
69 69
70 70
71int lua_getstack (lua_State *L, int level, lua_Debug *ar) { 71LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
72 StkId f = aux_stackedfunction(L, level, L->top); 72 StkId f = aux_stackedfunction(L, level, L->top);
73 if (f == NULL) return 0; /* there is no such level */ 73 if (f == NULL) return 0; /* there is no such level */
74 else { 74 else {
@@ -78,7 +78,7 @@ int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
78} 78}
79 79
80 80
81static int lua_nups (StkId f) { 81static int nups (StkId f) {
82 switch (ttype(f)) { 82 switch (ttype(f)) {
83 case LUA_TFUNCTION: 83 case LUA_TFUNCTION:
84 return clvalue(f)->nupvalues; 84 return clvalue(f)->nupvalues;
@@ -121,7 +121,7 @@ int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) {
121} 121}
122 122
123 123
124static int lua_currentpc (StkId f) { 124static int currentpc (StkId f) {
125 CallInfo *ci = infovalue(f); 125 CallInfo *ci = infovalue(f);
126 LUA_ASSERT(isLmark(f), "function has no pc"); 126 LUA_ASSERT(isLmark(f), "function has no pc");
127 if (ci->pc) 127 if (ci->pc)
@@ -131,13 +131,13 @@ static int lua_currentpc (StkId f) {
131} 131}
132 132
133 133
134static int lua_currentline (StkId f) { 134static int currentline (StkId f) {
135 if (!isLmark(f)) 135 if (!isLmark(f))
136 return -1; /* only active lua functions have current-line information */ 136 return -1; /* only active lua functions have current-line information */
137 else { 137 else {
138 CallInfo *ci = infovalue(f); 138 CallInfo *ci = infovalue(f);
139 int *lineinfo = ci->func->f.l->lineinfo; 139 int *lineinfo = ci->func->f.l->lineinfo;
140 return luaG_getline(lineinfo, lua_currentpc(f), 1, NULL); 140 return luaG_getline(lineinfo, currentpc(f), 1, NULL);
141 } 141 }
142} 142}
143 143
@@ -148,25 +148,27 @@ static Proto *getluaproto (StkId f) {
148} 148}
149 149
150 150
151const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int localnum) { 151LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar,
152 int localnum) {
152 const char *name; 153 const char *name;
153 StkId f = ar->_func; 154 StkId f = ar->_func;
154 Proto *fp = getluaproto(f); 155 Proto *fp = getluaproto(f);
155 if (!fp) return NULL; /* `f' is not a Lua function? */ 156 if (!fp) return NULL; /* `f' is not a Lua function? */
156 name = luaF_getlocalname(fp, localnum, lua_currentpc(f)); 157 name = luaF_getlocalname(fp, localnum, currentpc(f));
157 if (!name) return NULL; 158 if (!name) return NULL;
158 luaA_pushobject(L, (f+1)+(localnum-1)); /* push value */ 159 luaA_pushobject(L, (f+1)+(localnum-1)); /* push value */
159 return name; 160 return name;
160} 161}
161 162
162 163
163const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int localnum) { 164LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar,
165 int localnum) {
164 const char *name; 166 const char *name;
165 StkId f = ar->_func; 167 StkId f = ar->_func;
166 Proto *fp = getluaproto(f); 168 Proto *fp = getluaproto(f);
167 L->top--; /* pop new value */ 169 L->top--; /* pop new value */
168 if (!fp) return NULL; /* `f' is not a Lua function? */ 170 if (!fp) return NULL; /* `f' is not a Lua function? */
169 name = luaF_getlocalname(fp, localnum, lua_currentpc(f)); 171 name = luaF_getlocalname(fp, localnum, currentpc(f));
170 if (!name || name[0] == '*') return NULL; /* `*' starts private locals */ 172 if (!name || name[0] == '*') return NULL; /* `*' starts private locals */
171 *((f+1)+(localnum-1)) = *L->top; 173 *((f+1)+(localnum-1)) = *L->top;
172 return name; 174 return name;
@@ -180,7 +182,7 @@ static void infoLproto (lua_Debug *ar, Proto *f) {
180} 182}
181 183
182 184
183static void lua_funcinfo (lua_State *L, lua_Debug *ar, StkId func) { 185static void funcinfo (lua_State *L, lua_Debug *ar, StkId func) {
184 Closure *cl = NULL; 186 Closure *cl = NULL;
185 switch (ttype(func)) { 187 switch (ttype(func)) {
186 case LUA_TFUNCTION: 188 case LUA_TFUNCTION:
@@ -231,7 +233,7 @@ static const char *travglobals (lua_State *L, const TObject *o) {
231} 233}
232 234
233 235
234static void lua_getname (lua_State *L, StkId f, lua_Debug *ar) { 236static void getname (lua_State *L, StkId f, lua_Debug *ar) {
235 TObject o; 237 TObject o;
236 setnormalized(&o, f); 238 setnormalized(&o, f);
237 /* try to find a name for given function */ 239 /* try to find a name for given function */
@@ -244,7 +246,7 @@ static void lua_getname (lua_State *L, StkId f, lua_Debug *ar) {
244} 246}
245 247
246 248
247int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { 249LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
248 StkId func; 250 StkId func;
249 int isactive = (*what != '>'); 251 int isactive = (*what != '>');
250 if (isactive) 252 if (isactive)
@@ -256,21 +258,21 @@ int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
256 for (; *what; what++) { 258 for (; *what; what++) {
257 switch (*what) { 259 switch (*what) {
258 case 'S': { 260 case 'S': {
259 lua_funcinfo(L, ar, func); 261 funcinfo(L, ar, func);
260 break; 262 break;
261 } 263 }
262 case 'l': { 264 case 'l': {
263 ar->currentline = lua_currentline(func); 265 ar->currentline = currentline(func);
264 break; 266 break;
265 } 267 }
266 case 'u': { 268 case 'u': {
267 ar->nups = lua_nups(func); 269 ar->nups = nups(func);
268 break; 270 break;
269 } 271 }
270 case 'n': { 272 case 'n': {
271 ar->namewhat = (isactive) ? getfuncname(L, func, &ar->name) : NULL; 273 ar->namewhat = (isactive) ? getfuncname(L, func, &ar->name) : NULL;
272 if (ar->namewhat == NULL) 274 if (ar->namewhat == NULL)
273 lua_getname(L, func, ar); 275 getname(L, func, ar);
274 break; 276 break;
275 } 277 }
276 case 'f': { 278 case 'f': {
@@ -387,7 +389,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) {
387 return NULL; /* not an active Lua function */ 389 return NULL; /* not an active Lua function */
388 else { 390 else {
389 Proto *p = infovalue(func)->func->f.l; 391 Proto *p = infovalue(func)->func->f.l;
390 int pc = lua_currentpc(func); 392 int pc = currentpc(func);
391 int stackpos = obj - (func+1); /* func+1 == function base */ 393 int stackpos = obj - (func+1); /* func+1 == function base */
392 Instruction i = luaG_symbexec(p, pc, stackpos); 394 Instruction i = luaG_symbexec(p, pc, stackpos);
393 LUA_ASSERT(pc != -1, "function must be active"); 395 LUA_ASSERT(pc != -1, "function must be active");
@@ -419,7 +421,7 @@ static const char *getfuncname (lua_State *L, StkId f, const char **name) {
419 return NULL; /* not an active Lua function */ 421 return NULL; /* not an active Lua function */
420 else { 422 else {
421 Proto *p = infovalue(func)->func->f.l; 423 Proto *p = infovalue(func)->func->f.l;
422 int pc = lua_currentpc(func); 424 int pc = currentpc(func);
423 Instruction i; 425 Instruction i;
424 if (pc == -1) return NULL; /* function is not activated */ 426 if (pc == -1) return NULL; /* function is not activated */
425 i = p->code[pc]; 427 i = p->code[pc];