aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-24 13:45:33 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-24 13:45:33 -0200
commit71ae4801d66d9592b0fb08e4e78138b7a6e993d5 (patch)
treea683b5b3757efb979329bf513f1bd9fde3fb9d1f /ldebug.c
parent6fda6a530265268c01a83c31f8fc30e34753bbf1 (diff)
downloadlua-71ae4801d66d9592b0fb08e4e78138b7a6e993d5.tar.gz
lua-71ae4801d66d9592b0fb08e4e78138b7a6e993d5.tar.bz2
lua-71ae4801d66d9592b0fb08e4e78138b7a6e993d5.zip
macros LUA_ENTRY/LUA_EXIT to control exclusive access to Lua core
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c73
1 files changed, 51 insertions, 22 deletions
diff --git a/ldebug.c b/ldebug.c
index 3efe2613..7d5a150d 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.53 2001/01/18 15:59:09 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.54 2001/01/19 13:20:30 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,15 +41,21 @@ static int isLmark (StkId o) {
41 41
42 42
43LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) { 43LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) {
44 lua_Hook oldhook = L->callhook; 44 lua_Hook oldhook;
45 LUA_ENTRY;
46 oldhook = L->callhook;
45 L->callhook = func; 47 L->callhook = func;
48 LUA_EXIT;
46 return oldhook; 49 return oldhook;
47} 50}
48 51
49 52
50LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { 53LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) {
51 lua_Hook oldhook = L->linehook; 54 lua_Hook oldhook;
55 LUA_ENTRY;
56 oldhook = L->linehook;
52 L->linehook = func; 57 L->linehook = func;
58 LUA_EXIT;
53 return oldhook; 59 return oldhook;
54} 60}
55 61
@@ -68,12 +74,17 @@ static StkId aux_stackedfunction (lua_State *L, int level, StkId top) {
68 74
69 75
70LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { 76LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
71 StkId f = aux_stackedfunction(L, level, L->top); 77 StkId f;
72 if (f == NULL) return 0; /* there is no such level */ 78 int status;
79 LUA_ENTRY;
80 f = aux_stackedfunction(L, level, L->top);
81 if (f == NULL) status = 0; /* there is no such level */
73 else { 82 else {
74 ar->_func = f; 83 ar->_func = f;
75 return 1; 84 status = 1;
76 } 85 }
86 LUA_EXIT;
87 return status;
77} 88}
78 89
79 90
@@ -149,25 +160,39 @@ static Proto *getluaproto (StkId f) {
149 160
150LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { 161LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
151 const char *name; 162 const char *name;
152 StkId f = ar->_func; 163 StkId f;
153 Proto *fp = getluaproto(f); 164 Proto *fp;
154 if (!fp) return NULL; /* `f' is not a Lua function? */ 165 LUA_ENTRY;
155 name = luaF_getlocalname(fp, n, currentpc(f)); 166 name = NULL;
156 if (!name) return NULL; 167 f = ar->_func;
157 luaA_pushobject(L, (f+1)+(n-1)); /* push value */ 168 fp = getluaproto(f);
169 if (fp) { /* `f' is a Lua function? */
170 name = luaF_getlocalname(fp, n, currentpc(f));
171 if (name)
172 luaA_pushobject(L, (f+1)+(n-1)); /* push value */
173 }
174 LUA_EXIT;
158 return name; 175 return name;
159} 176}
160 177
161 178
162LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { 179LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
163 const char *name; 180 const char *name;
164 StkId f = ar->_func; 181 StkId f;
165 Proto *fp = getluaproto(f); 182 Proto *fp;
183 LUA_ENTRY;
184 name = NULL;
185 f = ar->_func;
186 fp = getluaproto(f);
166 L->top--; /* pop new value */ 187 L->top--; /* pop new value */
167 if (!fp) return NULL; /* `f' is not a Lua function? */ 188 if (fp) { /* `f' is a Lua function? */
168 name = luaF_getlocalname(fp, n, currentpc(f)); 189 name = luaF_getlocalname(fp, n, currentpc(f));
169 if (!name || name[0] == '(') return NULL; /* `(' starts private locals */ 190 if (!name || name[0] == '(') /* `(' starts private locals */
170 setobj((f+1)+(n-1), L->top); 191 name = NULL;
192 else
193 setobj((f+1)+(n-1), L->top);
194 }
195 LUA_EXIT;
171 return name; 196 return name;
172} 197}
173 198
@@ -189,7 +214,7 @@ static void funcinfo (lua_State *L, lua_Debug *ar, StkId func) {
189 cl = infovalue(func)->func; 214 cl = infovalue(func)->func;
190 break; 215 break;
191 default: 216 default:
192 lua_error(L, "value for `lua_getinfo' is not a function"); 217 luaD_error(L, "value for `lua_getinfo' is not a function");
193 } 218 }
194 if (cl->isC) { 219 if (cl->isC) {
195 ar->source = "=C"; 220 ar->source = "=C";
@@ -245,7 +270,10 @@ static void getname (lua_State *L, StkId f, lua_Debug *ar) {
245 270
246LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { 271LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
247 StkId func; 272 StkId func;
248 int isactive = (*what != '>'); 273 int isactive;
274 int status = 1;
275 LUA_ENTRY;
276 isactive = (*what != '>');
249 if (isactive) 277 if (isactive)
250 func = ar->_func; 278 func = ar->_func;
251 else { 279 else {
@@ -277,11 +305,12 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
277 incr_top; /* push function */ 305 incr_top; /* push function */
278 break; 306 break;
279 } 307 }
280 default: return 0; /* invalid option */ 308 default: status = 0; /* invalid option */
281 } 309 }
282 } 310 }
283 if (!isactive) L->top--; /* pop function */ 311 if (!isactive) L->top--; /* pop function */
284 return 1; 312 LUA_EXIT;
313 return status;
285} 314}
286 315
287 316