diff options
-rw-r--r-- | lapi.c | 32 | ||||
-rw-r--r-- | lapi.h | 8 | ||||
-rw-r--r-- | lauxlib.c | 16 | ||||
-rw-r--r-- | ldblib.c | 157 | ||||
-rw-r--r-- | ldebug.c | 213 | ||||
-rw-r--r-- | ldo.c | 43 | ||||
-rw-r--r-- | ldo.h | 8 | ||||
-rw-r--r-- | liolib.c | 48 | ||||
-rw-r--r-- | lstate.h | 6 | ||||
-rw-r--r-- | ltests.c | 6 | ||||
-rw-r--r-- | ltm.c | 4 | ||||
-rw-r--r-- | luadebug.h | 49 | ||||
-rw-r--r-- | lvm.c | 6 |
13 files changed, 287 insertions, 309 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.67 1999/12/30 18:27:03 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.68 2000/01/13 15:56:03 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -30,29 +30,12 @@ const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" | |||
30 | 30 | ||
31 | 31 | ||
32 | 32 | ||
33 | const lua_Type luaA_normtype[] = { /* ORDER LUA_T */ | ||
34 | LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, | ||
35 | LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, | ||
36 | LUA_T_LCLOSURE, LUA_T_CCLOSURE, | ||
37 | LUA_T_LCLOSURE, LUA_T_CCLOSURE, /* LUA_T_LCLMARK, LUA_T_CCLMARK */ | ||
38 | LUA_T_LPROTO, LUA_T_CPROTO /* LUA_T_LMARK, LUA_T_CMARK */ | ||
39 | }; | ||
40 | |||
41 | |||
42 | void luaA_setnormalized (TObject *d, const TObject *s) { | ||
43 | d->value = s->value; | ||
44 | d->ttype = luaA_normalizedtype(s); | ||
45 | } | ||
46 | |||
47 | 33 | ||
48 | const TObject *luaA_protovalue (const TObject *o) { | 34 | const TObject *luaA_protovalue (const TObject *o) { |
49 | switch (luaA_normalizedtype(o)) { | 35 | switch (ttype(o)) { |
50 | case LUA_T_CCLOSURE: case LUA_T_LCLOSURE: | 36 | case LUA_T_CCLOSURE: case LUA_T_LCLOSURE: |
51 | return protovalue(o); | 37 | return protovalue(o); |
52 | default: | 38 | default: |
53 | LUA_ASSERT(L, luaA_normalizedtype(o) == LUA_T_LPROTO || | ||
54 | luaA_normalizedtype(o) == LUA_T_CPROTO, | ||
55 | "invalid `function'"); | ||
56 | return o; | 39 | return o; |
57 | } | 40 | } |
58 | } | 41 | } |
@@ -107,7 +90,7 @@ int lua_callfunction (lua_State *L, lua_Object function) { | |||
107 | return 1; | 90 | return 1; |
108 | else { | 91 | else { |
109 | luaD_openstack(L, L->Cstack.base); | 92 | luaD_openstack(L, L->Cstack.base); |
110 | luaA_setnormalized(L->Cstack.base, function); | 93 | *L->Cstack.base = *function; |
111 | return luaD_protectedrun(L); | 94 | return luaD_protectedrun(L); |
112 | } | 95 | } |
113 | } | 96 | } |
@@ -248,12 +231,7 @@ int lua_equal(lua_State *L, lua_Object o1, lua_Object o2) { | |||
248 | UNUSED(L); | 231 | UNUSED(L); |
249 | if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT) | 232 | if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT) |
250 | return (o1 == o2); | 233 | return (o1 == o2); |
251 | else { | 234 | else return luaO_equalObj(o1, o2); |
252 | TObject obj1, obj2; | ||
253 | luaA_setnormalized(&obj1, o1); | ||
254 | luaA_setnormalized(&obj2, o2); | ||
255 | return luaO_equalObj(&obj1, &obj2); | ||
256 | } | ||
257 | } | 235 | } |
258 | 236 | ||
259 | 237 | ||
@@ -344,7 +322,7 @@ void luaA_pushobject (lua_State *L, const TObject *o) { | |||
344 | void lua_pushobject (lua_State *L, lua_Object o) { | 322 | void lua_pushobject (lua_State *L, lua_Object o) { |
345 | if (o == LUA_NOOBJECT) | 323 | if (o == LUA_NOOBJECT) |
346 | lua_error(L, "API error - attempt to push a NOOBJECT"); | 324 | lua_error(L, "API error - attempt to push a NOOBJECT"); |
347 | luaA_setnormalized(L->top, o); | 325 | *L->top = *o; |
348 | incr_top; | 326 | incr_top; |
349 | } | 327 | } |
350 | 328 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.h,v 1.11 1999/12/14 18:33:29 roberto Exp roberto $ | 2 | ** $Id: lapi.h,v 1.12 1999/12/23 18:19:57 roberto Exp roberto $ |
3 | ** Auxiliary functions from Lua API | 3 | ** Auxiliary functions from Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -11,12 +11,6 @@ | |||
11 | #include "lobject.h" | 11 | #include "lobject.h" |
12 | 12 | ||
13 | 13 | ||
14 | extern const lua_Type luaA_normtype[]; | ||
15 | |||
16 | #define luaA_normalizedtype(o) (luaA_normtype[-ttype(o)]) | ||
17 | |||
18 | |||
19 | void luaA_setnormalized (TObject *d, const TObject *s); | ||
20 | void luaA_checkCparams (lua_State *L, int nParams); | 14 | void luaA_checkCparams (lua_State *L, int nParams); |
21 | const TObject *luaA_protovalue (const TObject *o); | 15 | const TObject *luaA_protovalue (const TObject *o); |
22 | void luaA_pushobject (lua_State *L, const TObject *o); | 16 | void luaA_pushobject (lua_State *L, const TObject *o); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.23 1999/12/27 17:33:22 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.24 1999/12/28 11:52:49 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -31,14 +31,14 @@ int luaL_findstring (const char *name, const char *const list[]) { | |||
31 | } | 31 | } |
32 | 32 | ||
33 | void luaL_argerror (lua_State *L, int narg, const char *extramsg) { | 33 | void luaL_argerror (lua_State *L, int narg, const char *extramsg) { |
34 | lua_Function f = lua_stackedfunction(L, 0); | 34 | lua_Dbgactreg ar; |
35 | const char *funcname; | 35 | lua_getstack(L, 0, &ar); |
36 | lua_getobjname(L, f, &funcname); | 36 | lua_getinfo(L, "nu", &ar); |
37 | narg -= lua_nups(L, f); | 37 | narg -= ar.nups; |
38 | if (funcname == NULL) | 38 | if (ar.name == NULL) |
39 | funcname = "?"; | 39 | ar.name = "?"; |
40 | luaL_verror(L, "bad argument #%d to `%.50s' (%.100s)", | 40 | luaL_verror(L, "bad argument #%d to `%.50s' (%.100s)", |
41 | narg, funcname, extramsg); | 41 | narg, ar.name, extramsg); |
42 | } | 42 | } |
43 | 43 | ||
44 | 44 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.8 1999/11/22 17:39:51 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.9 1999/12/21 18:04:41 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 | */ |
@@ -33,113 +33,73 @@ static void settabsi (lua_State *L, lua_Object t, const char *i, int v) { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | 35 | ||
36 | static lua_Object getfuncinfo (lua_State *L, lua_Object func) { | 36 | static void settabso (lua_State *L, lua_Object t, const char *i, lua_Object v) { |
37 | lua_Object result = lua_createtable(L); | 37 | lua_pushobject(L, t); |
38 | const char *str; | 38 | lua_pushstring(L, i); |
39 | int line; | 39 | lua_pushobject(L, v); |
40 | lua_funcinfo(L, func, &str, &line); | 40 | lua_settable(L); |
41 | if (line == -1) /* C function? */ | ||
42 | settabss(L, result, "kind", "C"); | ||
43 | else if (line == 0) { /* "main"? */ | ||
44 | settabss(L, result, "kind", "chunk"); | ||
45 | settabss(L, result, "source", str); | ||
46 | } | ||
47 | else { /* Lua function */ | ||
48 | settabss(L, result, "kind", "Lua"); | ||
49 | settabsi(L, result, "def_line", line); | ||
50 | settabss(L, result, "source", str); | ||
51 | } | ||
52 | if (line != 0) { /* is it not a "main"? */ | ||
53 | const char *kind = lua_getobjname(L, func, &str); | ||
54 | if (*kind) { | ||
55 | settabss(L, result, "name", str); | ||
56 | settabss(L, result, "where", kind); | ||
57 | } | ||
58 | } | ||
59 | return result; | ||
60 | } | 41 | } |
61 | 42 | ||
62 | 43 | ||
63 | static void getstack (lua_State *L) { | 44 | static void getstack (lua_State *L) { |
64 | lua_Object func = lua_stackedfunction(L, luaL_check_int(L, 1)); | 45 | lua_Dbgactreg ar; |
65 | if (func == LUA_NOOBJECT) /* level out of range? */ | 46 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ |
66 | return; | 47 | return; |
67 | else { | 48 | else { |
68 | lua_Object result = getfuncinfo(L, func); | 49 | const char *options = luaL_check_string(L, 2); |
69 | int currline = lua_currentline(L, func); | 50 | lua_Object res = lua_createtable(L); |
70 | if (currline > 0) | 51 | if (!lua_getinfo(L, options, &ar)) |
71 | settabsi(L, result, "current", currline); | 52 | luaL_argerror(L, 2, "invalid option"); |
72 | lua_pushobject(L, result); | 53 | for ( ;*options; options++) { |
73 | lua_pushstring(L, "func"); | 54 | switch (*options) { |
74 | lua_pushobject(L, func); | 55 | case 'S': |
75 | lua_settable(L); /* result.func = func */ | 56 | settabss(L, res, "source", ar.source); |
76 | lua_pushobject(L, result); | 57 | settabsi(L, res, "linedefined", ar.linedefined); |
77 | } | 58 | settabss(L, res, "what", ar.what); |
78 | } | 59 | break; |
79 | 60 | case 'l': | |
80 | 61 | settabsi(L, res, "currentline", ar.currentline); | |
81 | static void funcinfo (lua_State *L) { | 62 | break; |
82 | lua_pushobject(L, getfuncinfo(L, luaL_functionarg(L, 1))); | 63 | case 'u': |
83 | } | 64 | settabsi(L, res, "nups", ar.nups); |
84 | 65 | break; | |
85 | 66 | case 'n': | |
86 | static int findlocal (lua_State *L, lua_Object func, int arg) { | 67 | settabss(L, res, "name", ar.name); |
87 | lua_Object v = lua_getparam(L, arg); | 68 | settabss(L, res, "namewhat", ar.namewhat); |
88 | if (lua_isnumber(L, v)) | 69 | break; |
89 | return (int)lua_getnumber(L, v); | 70 | case 'f': |
90 | else { | 71 | settabso(L, res, "func", ar.func); |
91 | const char *name = luaL_check_string(L, arg); | 72 | break; |
92 | int i = 0; | 73 | |
93 | int result = -1; | 74 | } |
94 | const char *vname; | ||
95 | while (lua_getlocal(L, func, ++i, &vname) != LUA_NOOBJECT) { | ||
96 | if (strcmp(name, vname) == 0) | ||
97 | result = i; /* keep looping to get the last var with this name */ | ||
98 | } | 75 | } |
99 | if (result == -1) | 76 | lua_pushobject(L, res); |
100 | luaL_verror(L, "no local variable `%.50s' at given level", name); | ||
101 | return result; | ||
102 | } | 77 | } |
103 | } | 78 | } |
104 | 79 | ||
105 | 80 | ||
106 | static void getlocal (lua_State *L) { | 81 | static void getlocal (lua_State *L) { |
107 | lua_Object func = lua_stackedfunction(L, luaL_check_int(L, 1)); | 82 | lua_Dbgactreg ar; |
108 | lua_Object val; | 83 | lua_Dbglocvar lvar; |
109 | const char *name; | 84 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ |
110 | if (func == LUA_NOOBJECT) /* level out of range? */ | 85 | luaL_argerror(L, 1, "level out of range"); |
111 | return; /* return nil */ | 86 | lvar.index = luaL_check_int(L, 2); |
112 | else if (lua_getparam(L, 2) != LUA_NOOBJECT) { /* 2nd argument? */ | 87 | if (lua_getlocal(L, &ar, &lvar)) { |
113 | if ((val = lua_getlocal(L, func, findlocal(L, func, 2), &name)) != LUA_NOOBJECT) { | 88 | lua_pushstring(L, lvar.name); |
114 | lua_pushobject(L, val); | 89 | lua_pushobject(L, lvar.value); |
115 | lua_pushstring(L, name); | ||
116 | } | ||
117 | /* else return nil */ | ||
118 | } | ||
119 | else { /* collect all locals in a table */ | ||
120 | lua_Object result = lua_createtable(L); | ||
121 | int i; | ||
122 | for (i=1; ;i++) { | ||
123 | if ((val = lua_getlocal(L, func, i, &name)) == LUA_NOOBJECT) | ||
124 | break; | ||
125 | lua_pushobject(L, result); | ||
126 | lua_pushstring(L, name); | ||
127 | lua_pushobject(L, val); | ||
128 | lua_settable(L); /* result[name] = value */ | ||
129 | } | ||
130 | lua_pushobject(L, result); | ||
131 | } | 90 | } |
132 | } | 91 | } |
133 | 92 | ||
134 | 93 | ||
135 | static void setlocal (lua_State *L) { | 94 | static void setlocal (lua_State *L) { |
136 | lua_Object func = lua_stackedfunction(L, luaL_check_int(L, 1)); | 95 | lua_Dbgactreg ar; |
137 | int numvar; | 96 | lua_Dbglocvar lvar; |
138 | luaL_arg_check(L, func != LUA_NOOBJECT, 1, "level out of range"); | 97 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ |
139 | numvar = findlocal(L, func, 2); | 98 | luaL_argerror(L, 1, "level out of range"); |
140 | lua_pushobject(L, luaL_nonnullarg(L, 3)); | 99 | lvar.index = luaL_check_int(L, 2); |
141 | if (!lua_setlocal(L, func, numvar)) | 100 | lvar.value = luaL_nonnullarg(L, 3); |
142 | lua_error(L, "no such local variable"); | 101 | if (lua_setlocal(L, &ar, &lvar)) |
102 | lua_pushstring(L, lvar.name); | ||
143 | } | 103 | } |
144 | 104 | ||
145 | 105 | ||
@@ -149,21 +109,17 @@ static int callhook = LUA_NOREF; /* Lua reference to call hook function */ | |||
149 | 109 | ||
150 | 110 | ||
151 | 111 | ||
152 | static void linef (lua_State *L, int line) { | 112 | static void linef (lua_State *L, lua_Dbgactreg *ar) { |
153 | if (linehook != LUA_NOREF) { | 113 | if (linehook != LUA_NOREF) { |
154 | lua_pushnumber(L, line); | 114 | lua_pushnumber(L, ar->currentline); |
155 | lua_callfunction(L, lua_getref(L, linehook)); | 115 | lua_callfunction(L, lua_getref(L, linehook)); |
156 | } | 116 | } |
157 | } | 117 | } |
158 | 118 | ||
159 | 119 | ||
160 | static void callf (lua_State *L, lua_Function f, const char *file, int line) { | 120 | static void callf (lua_State *L, lua_Dbgactreg *ar) { |
161 | if (callhook != LUA_NOREF) { | 121 | if (callhook != LUA_NOREF) { |
162 | if (f != LUA_NOOBJECT) { | 122 | lua_pushstring(L, ar->event); |
163 | lua_pushobject(L, f); | ||
164 | lua_pushstring(L, file); | ||
165 | lua_pushnumber(L, line); | ||
166 | } | ||
167 | lua_callfunction(L, lua_getref(L, callhook)); | 123 | lua_callfunction(L, lua_getref(L, callhook)); |
168 | } | 124 | } |
169 | } | 125 | } |
@@ -200,7 +156,6 @@ static void setlinehook (lua_State *L) { | |||
200 | 156 | ||
201 | 157 | ||
202 | static const struct luaL_reg dblib[] = { | 158 | static const struct luaL_reg dblib[] = { |
203 | {"funcinfo", funcinfo}, | ||
204 | {"getlocal", getlocal}, | 159 | {"getlocal", getlocal}, |
205 | {"getstack", getstack}, | 160 | {"getstack", getstack}, |
206 | {"setcallhook", setcallhook}, | 161 | {"setcallhook", setcallhook}, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.3 1999/12/29 16:31:15 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.4 1999/12/30 18:28:40 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 | */ |
@@ -10,6 +10,7 @@ | |||
10 | #include "lapi.h" | 10 | #include "lapi.h" |
11 | #include "lauxlib.h" | 11 | #include "lauxlib.h" |
12 | #include "ldebug.h" | 12 | #include "ldebug.h" |
13 | #include "ldo.h" | ||
13 | #include "lfunc.h" | 14 | #include "lfunc.h" |
14 | #include "lobject.h" | 15 | #include "lobject.h" |
15 | #include "lstate.h" | 16 | #include "lstate.h" |
@@ -19,22 +20,38 @@ | |||
19 | #include "luadebug.h" | 20 | #include "luadebug.h" |
20 | 21 | ||
21 | 22 | ||
22 | static int hasdebuginfo (lua_State *L, lua_Function f) { | 23 | static const lua_Type normtype[] = { /* ORDER LUA_T */ |
23 | return (f+1 < L->top && (f+1)->ttype == LUA_T_LINE); | 24 | LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, |
25 | LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, | ||
26 | LUA_T_LCLOSURE, LUA_T_CCLOSURE, | ||
27 | LUA_T_LCLOSURE, LUA_T_CCLOSURE, /* LUA_T_LCLMARK, LUA_T_CCLMARK */ | ||
28 | LUA_T_LPROTO, LUA_T_CPROTO /* LUA_T_LMARK, LUA_T_CMARK */ | ||
29 | }; | ||
30 | |||
31 | |||
32 | static void setnormalized (TObject *d, const TObject *s) { | ||
33 | d->value = s->value; | ||
34 | d->ttype = normtype[-ttype(s)]; | ||
24 | } | 35 | } |
25 | 36 | ||
26 | 37 | ||
27 | lua_LHFunction lua_setlinehook (lua_State *L, lua_LHFunction func) { | 38 | |
28 | lua_LHFunction old = L->linehook; | 39 | static int hasdebuginfo (lua_State *L, StkId f) { |
29 | L->linehook = func; | 40 | return (f+1 < L->top && (f+1)->ttype == LUA_T_LINE); |
30 | return old; | ||
31 | } | 41 | } |
32 | 42 | ||
33 | 43 | ||
34 | lua_CHFunction lua_setcallhook (lua_State *L, lua_CHFunction func) { | 44 | lua_Dbghook lua_setcallhook (lua_State *L, lua_Dbghook func) { |
35 | lua_CHFunction old = L->callhook; | 45 | lua_Dbghook oldhook = L->callhook; |
36 | L->callhook = func; | 46 | L->callhook = func; |
37 | return old; | 47 | return oldhook; |
48 | } | ||
49 | |||
50 | |||
51 | lua_Dbghook lua_setlinehook (lua_State *L, lua_Dbghook func) { | ||
52 | lua_Dbghook oldhook = L->linehook; | ||
53 | L->linehook = func; | ||
54 | return oldhook; | ||
38 | } | 55 | } |
39 | 56 | ||
40 | 57 | ||
@@ -45,7 +62,7 @@ int lua_setdebug (lua_State *L, int debug) { | |||
45 | } | 62 | } |
46 | 63 | ||
47 | 64 | ||
48 | static lua_Function aux_stackedfunction (lua_State *L, int level, StkId top) { | 65 | static StkId aux_stackedfunction (lua_State *L, int level, StkId top) { |
49 | int i; | 66 | int i; |
50 | for (i = (top-1)-L->stack; i>=0; i--) { | 67 | for (i = (top-1)-L->stack; i>=0; i--) { |
51 | if (is_T_MARK(L->stack[i].ttype)) { | 68 | if (is_T_MARK(L->stack[i].ttype)) { |
@@ -54,18 +71,23 @@ static lua_Function aux_stackedfunction (lua_State *L, int level, StkId top) { | |||
54 | level--; | 71 | level--; |
55 | } | 72 | } |
56 | } | 73 | } |
57 | return LUA_NOOBJECT; | 74 | return NULL; |
58 | } | 75 | } |
59 | 76 | ||
60 | 77 | ||
61 | lua_Function lua_stackedfunction (lua_State *L, int level) { | 78 | int lua_getstack (lua_State *L, int level, lua_Dbgactreg *ar) { |
62 | return aux_stackedfunction(L, level, L->top); | 79 | StkId f = aux_stackedfunction(L, level, L->top); |
80 | if (f == NULL) return 0; /* there is no such level */ | ||
81 | else { | ||
82 | ar->_func = f; | ||
83 | return 1; | ||
84 | } | ||
63 | } | 85 | } |
64 | 86 | ||
65 | 87 | ||
66 | static const char *luaG_getname (lua_State *L, const char **name, StkId top) { | 88 | static const char *luaG_getname (lua_State *L, const char **name, StkId top) { |
67 | lua_Function f = aux_stackedfunction(L, 0, top); | 89 | StkId f = aux_stackedfunction(L, 0, top); |
68 | if (f == LUA_NOOBJECT || !hasdebuginfo(L, f) || ttype(f+2) == LUA_T_NIL) | 90 | if (f == NULL || !hasdebuginfo(L, f) || ttype(f+2) == LUA_T_NIL) |
69 | return ""; /* no name available */ | 91 | return ""; /* no name available */ |
70 | else { | 92 | else { |
71 | int i = (f+2)->value.i; | 93 | int i = (f+2)->value.i; |
@@ -79,10 +101,10 @@ static const char *luaG_getname (lua_State *L, const char **name, StkId top) { | |||
79 | } | 101 | } |
80 | 102 | ||
81 | 103 | ||
82 | int lua_nups (lua_State *L, lua_Function f) { | 104 | static int lua_nups (StkId f) { |
83 | UNUSED(L); | 105 | switch (ttype(f)) { |
84 | switch (luaA_normalizedtype(f)) { | ||
85 | case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: | 106 | case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: |
107 | case LUA_T_LCLMARK: case LUA_T_CCLMARK: | ||
86 | return f->value.cl->nelems; | 108 | return f->value.cl->nelems; |
87 | default: | 109 | default: |
88 | return 0; | 110 | return 0; |
@@ -90,67 +112,66 @@ int lua_nups (lua_State *L, lua_Function f) { | |||
90 | } | 112 | } |
91 | 113 | ||
92 | 114 | ||
93 | int lua_currentline (lua_State *L, lua_Function f) { | 115 | static int lua_currentline (lua_State *L, StkId f) { |
94 | return hasdebuginfo(L, f) ? (f+1)->value.i : -1; | 116 | return hasdebuginfo(L, f) ? (f+1)->value.i : -1; |
95 | } | 117 | } |
96 | 118 | ||
97 | 119 | ||
98 | lua_Object lua_getlocal (lua_State *L, lua_Function f, int local_number, | 120 | static TProtoFunc *getluaproto (StkId f) { |
99 | const char **name) { | 121 | if (ttype(f) == LUA_T_LMARK) |
100 | /* check whether `f' is a Lua function */ | 122 | return f->value.tf; |
101 | if (lua_tag(L, f) != LUA_T_LPROTO) | 123 | else if (ttype(f) == LUA_T_LCLMARK) |
102 | return LUA_NOOBJECT; | 124 | return protovalue(f)->value.tf; |
103 | else { | 125 | else return NULL; |
104 | TProtoFunc *fp = luaA_protovalue(f)->value.tf; | ||
105 | *name = luaF_getlocalname(fp, local_number, lua_currentline(L, f)); | ||
106 | if (*name) { | ||
107 | /* if "*name", there must be a LUA_T_LINE and a NAME */ | ||
108 | /* therefore, f+3 points to function base */ | ||
109 | LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); | ||
110 | return luaA_putluaObject(L, (f+3)+(local_number-1)); | ||
111 | } | ||
112 | else | ||
113 | return LUA_NOOBJECT; | ||
114 | } | ||
115 | } | 126 | } |
116 | 127 | ||
117 | 128 | ||
118 | int lua_setlocal (lua_State *L, lua_Function f, int local_number) { | 129 | int lua_getlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) { |
119 | /* check whether `f' is a Lua function */ | 130 | StkId f = ar->_func; |
120 | if (lua_tag(L, f) != LUA_T_LPROTO) | 131 | TProtoFunc *fp = getluaproto(f); |
121 | return 0; | 132 | if (!fp) return 0; /* `f' is not a Lua function? */ |
122 | else { | 133 | v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); |
123 | TProtoFunc *fp = luaA_protovalue(f)->value.tf; | 134 | if (!v->name) return 0; |
124 | const char *name = luaF_getlocalname(fp, local_number, | 135 | /* if `name', there must be a LUA_T_LINE and a NAME */ |
125 | lua_currentline(L, f)); | 136 | /* therefore, f+3 points to function base */ |
126 | luaA_checkCparams(L, 1); | 137 | LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); |
127 | --L->top; | 138 | v->value = luaA_putluaObject(L, (f+3)+(v->index-1)); |
128 | if (name) { | 139 | return 1; |
129 | LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); | ||
130 | *((f+3)+(local_number-1)) = *L->top; | ||
131 | return 1; | ||
132 | } | ||
133 | else | ||
134 | return 0; | ||
135 | } | ||
136 | } | 140 | } |
137 | 141 | ||
138 | 142 | ||
139 | void lua_funcinfo (lua_State *L, lua_Object func, | 143 | int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) { |
140 | const char **source, int *linedefined) { | 144 | StkId f = ar->_func; |
141 | if (!lua_isfunction(L, func)) | 145 | TProtoFunc *fp = getluaproto(f); |
142 | lua_error(L, "API error - `funcinfo' called with a non-function value"); | 146 | if (!fp) return 0; /* `f' is not a Lua function? */ |
143 | else { | 147 | v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); |
144 | const TObject *f = luaA_protovalue(func); | 148 | if (!v->name) return 0; |
145 | if (luaA_normalizedtype(f) == LUA_T_LPROTO) { | 149 | LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); |
146 | *source = tfvalue(f)->source->str; | 150 | *((f+3)+(v->index-1)) = *v->value; |
147 | *linedefined = tfvalue(f)->lineDefined; | 151 | return 1; |
148 | } | 152 | } |
149 | else { | 153 | |
150 | *source = "(C)"; | 154 | |
151 | *linedefined = -1; | 155 | static void lua_funcinfo (lua_Dbgactreg *ar) { |
152 | } | 156 | StkId func = ar->_func; |
157 | switch (ttype(func)) { | ||
158 | case LUA_T_LPROTO: case LUA_T_LMARK: | ||
159 | ar->source = tfvalue(func)->source->str; | ||
160 | ar->linedefined = tfvalue(func)->lineDefined; | ||
161 | ar->what = "Lua"; | ||
162 | break; | ||
163 | case LUA_T_LCLOSURE: case LUA_T_LCLMARK: | ||
164 | ar->source = tfvalue(protovalue(func))->source->str; | ||
165 | ar->linedefined = tfvalue(protovalue(func))->lineDefined; | ||
166 | ar->what = "Lua"; | ||
167 | break; | ||
168 | default: | ||
169 | ar->source = "(C)"; | ||
170 | ar->linedefined = -1; | ||
171 | ar->what = "C"; | ||
153 | } | 172 | } |
173 | if (ar->linedefined == 0) | ||
174 | ar->what = "main"; | ||
154 | } | 175 | } |
155 | 176 | ||
156 | 177 | ||
@@ -159,28 +180,56 @@ static int checkfunc (lua_State *L, TObject *o) { | |||
159 | } | 180 | } |
160 | 181 | ||
161 | 182 | ||
162 | const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) { | 183 | static void lua_getobjname (lua_State *L, StkId f, lua_Dbgactreg *ar) { |
163 | GlobalVar *g; | 184 | GlobalVar *g; |
164 | if (is_T_MARK(ttype(o))) { /* `o' is an active function? */ | 185 | ar->namewhat = luaG_getname(L, &ar->name, f); /* caller debug information */ |
165 | /* look for caller debug information */ | 186 | if (*ar->namewhat) return; |
166 | const char *kind = luaG_getname(L, name, o); | ||
167 | if (*kind) return kind; | ||
168 | /* else go through */ | ||
169 | } | ||
170 | /* try to find a name for given function */ | 187 | /* try to find a name for given function */ |
171 | luaA_setnormalized(L->top, o); /* to be used by `checkfunc' */ | 188 | setnormalized(L->top, f); /* to be used by `checkfunc' */ |
172 | for (g=L->rootglobal; g; g=g->next) { | 189 | for (g=L->rootglobal; g; g=g->next) { |
173 | if (checkfunc(L, &g->value)) { | 190 | if (checkfunc(L, &g->value)) { |
174 | *name = g->name->str; | 191 | ar->name = g->name->str; |
175 | return "global"; | 192 | ar->namewhat = "global"; |
193 | return; | ||
176 | } | 194 | } |
177 | } | 195 | } |
178 | /* not found: try tag methods */ | 196 | /* not found: try tag methods */ |
179 | if ((*name = luaT_travtagmethods(L, checkfunc)) != NULL) | 197 | if ((ar->name = luaT_travtagmethods(L, checkfunc)) != NULL) |
180 | return "tag-method"; | 198 | ar->namewhat = "tag-method"; |
181 | else return ""; /* not found at all */ | 199 | else ar->namewhat = ""; /* not found at all */ |
200 | } | ||
201 | |||
202 | |||
203 | int lua_getinfo (lua_State *L, const char *what, lua_Dbgactreg *ar) { | ||
204 | StkId func = ar->_func; | ||
205 | LUA_ASSERT(L, is_T_MARK(ttype(func)), "invalid activation record"); | ||
206 | for ( ;*what; what++) { | ||
207 | switch (*what) { | ||
208 | case 'S': | ||
209 | lua_funcinfo(ar); | ||
210 | break; | ||
211 | case 'l': | ||
212 | ar->currentline = lua_currentline(L, func); | ||
213 | break; | ||
214 | case 'u': | ||
215 | ar->nups = lua_nups(func); | ||
216 | break; | ||
217 | case 'n': | ||
218 | lua_getobjname(L, func, ar); | ||
219 | break; | ||
220 | case 'f': | ||
221 | setnormalized(L->top, func); | ||
222 | incr_top; | ||
223 | ar->func = luaA_putObjectOnTop(L); | ||
224 | break; | ||
225 | default: return 0; /* invalid option */ | ||
226 | } | ||
227 | } | ||
228 | return 1; | ||
182 | } | 229 | } |
183 | 230 | ||
231 | |||
232 | |||
184 | static void call_index_error (lua_State *L, TObject *o, const char *tp, | 233 | static void call_index_error (lua_State *L, TObject *o, const char *tp, |
185 | const char *v) { | 234 | const char *v) { |
186 | const char *name; | 235 | const char *name; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.64 1999/12/30 18:40:57 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.65 2000/01/13 15:56:03 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -55,8 +55,9 @@ void luaD_checkstack (lua_State *L, int n) { | |||
55 | lua_error(L, "BAD STACK OVERFLOW! DATA CORRUPTED!!"); | 55 | lua_error(L, "BAD STACK OVERFLOW! DATA CORRUPTED!!"); |
56 | } | 56 | } |
57 | else { | 57 | else { |
58 | lua_Dbgactreg dummy; | ||
58 | L->stack_last += EXTRA_STACK; /* to be used by error message */ | 59 | L->stack_last += EXTRA_STACK; /* to be used by error message */ |
59 | if (lua_stackedfunction(L, L->stacksize/SLOTS_PER_F) == LUA_NOOBJECT) { | 60 | if (lua_getstack(L, L->stacksize/SLOTS_PER_F, &dummy) == 0) { |
60 | /* too few funcs on stack: doesn't look like a recursion loop */ | 61 | /* too few funcs on stack: doesn't look like a recursion loop */ |
61 | lua_error(L, "Lua2C - C2Lua overflow"); | 62 | lua_error(L, "Lua2C - C2Lua overflow"); |
62 | } | 63 | } |
@@ -100,13 +101,17 @@ void luaD_openstack (lua_State *L, StkId pos) { | |||
100 | } | 101 | } |
101 | 102 | ||
102 | 103 | ||
103 | void luaD_lineHook (lua_State *L, int line) { | 104 | void luaD_lineHook (lua_State *L, StkId func, int line) { |
104 | if (L->allowhooks) { | 105 | if (L->allowhooks) { |
106 | lua_Dbgactreg ar; | ||
105 | struct C_Lua_Stack oldCLS = L->Cstack; | 107 | struct C_Lua_Stack oldCLS = L->Cstack; |
106 | StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top; | 108 | StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top; |
107 | L->Cstack.num = 0; | 109 | L->Cstack.num = 0; |
110 | ar._func = func; | ||
111 | ar.event = "line"; | ||
112 | ar.currentline = line; | ||
108 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | 113 | L->allowhooks = 0; /* cannot call hooks inside a hook */ |
109 | (*L->linehook)(L, line); | 114 | (*L->linehook)(L, &ar); |
110 | L->allowhooks = 1; | 115 | L->allowhooks = 1; |
111 | L->top = old_top; | 116 | L->top = old_top; |
112 | L->Cstack = oldCLS; | 117 | L->Cstack = oldCLS; |
@@ -114,29 +119,17 @@ void luaD_lineHook (lua_State *L, int line) { | |||
114 | } | 119 | } |
115 | 120 | ||
116 | 121 | ||
117 | void luaD_callHook (lua_State *L, StkId func, lua_CHFunction callhook, | 122 | void luaD_callHook (lua_State *L, StkId func, lua_Dbghook callhook, |
118 | int isreturn) { | 123 | const char *event) { |
119 | if (L->allowhooks) { | 124 | if (L->allowhooks) { |
125 | lua_Dbgactreg ar; | ||
120 | struct C_Lua_Stack oldCLS = L->Cstack; | 126 | struct C_Lua_Stack oldCLS = L->Cstack; |
121 | StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top; | 127 | StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top; |
122 | L->Cstack.num = 0; | 128 | L->Cstack.num = 0; |
129 | ar._func = func; | ||
130 | ar.event = event; | ||
123 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | 131 | L->allowhooks = 0; /* cannot call hooks inside a hook */ |
124 | if (isreturn) | 132 | callhook(L, &ar); |
125 | callhook(L, LUA_NOOBJECT, "(return)", 0); | ||
126 | else { | ||
127 | switch (ttype(func)) { | ||
128 | case LUA_T_LPROTO: | ||
129 | callhook(L, func, tfvalue(func)->source->str, | ||
130 | tfvalue(func)->lineDefined); | ||
131 | break; | ||
132 | case LUA_T_LCLOSURE: | ||
133 | callhook(L, func, tfvalue(protovalue(func))->source->str, | ||
134 | tfvalue(protovalue(func))->lineDefined); | ||
135 | break; | ||
136 | default: | ||
137 | callhook(L, func, "(C)", -1); | ||
138 | } | ||
139 | } | ||
140 | L->allowhooks = 1; | 133 | L->allowhooks = 1; |
141 | L->top = old_top; | 134 | L->top = old_top; |
142 | L->Cstack = oldCLS; | 135 | L->Cstack = oldCLS; |
@@ -157,7 +150,7 @@ static StkId callC (lua_State *L, lua_CFunction f, StkId base) { | |||
157 | L->Cstack.lua2C = base; | 150 | L->Cstack.lua2C = base; |
158 | L->Cstack.base = L->top; | 151 | L->Cstack.base = L->top; |
159 | if (L->callhook) | 152 | if (L->callhook) |
160 | luaD_callHook(L, base-1, L->callhook, 0); | 153 | luaD_callHook(L, base-1, L->callhook, "call"); |
161 | (*f)(L); /* do the actual call */ | 154 | (*f)(L); /* do the actual call */ |
162 | firstResult = L->Cstack.base; | 155 | firstResult = L->Cstack.base; |
163 | L->Cstack = oldCLS; | 156 | L->Cstack = oldCLS; |
@@ -195,7 +188,7 @@ void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) { | |||
195 | */ | 188 | */ |
196 | void luaD_call (lua_State *L, StkId func, int nResults) { | 189 | void luaD_call (lua_State *L, StkId func, int nResults) { |
197 | StkId firstResult; | 190 | StkId firstResult; |
198 | lua_CHFunction callhook = L->callhook; | 191 | lua_Dbghook callhook = L->callhook; |
199 | retry: /* for `function' tag method */ | 192 | retry: /* for `function' tag method */ |
200 | switch (ttype(func)) { | 193 | switch (ttype(func)) { |
201 | case LUA_T_CPROTO: | 194 | case LUA_T_CPROTO: |
@@ -228,7 +221,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
228 | } | 221 | } |
229 | } | 222 | } |
230 | if (callhook) /* same hook that was active at entry */ | 223 | if (callhook) /* same hook that was active at entry */ |
231 | luaD_callHook(L, NULL, callhook, 1); /* `return' hook */ | 224 | luaD_callHook(L, func, callhook, "return"); |
232 | /* adjust the number of results */ | 225 | /* adjust the number of results */ |
233 | if (nResults == MULT_RET) | 226 | if (nResults == MULT_RET) |
234 | nResults = L->top - firstResult; | 227 | nResults = L->top - firstResult; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.h,v 1.15 1999/12/21 18:04:41 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 1.16 1999/12/30 18:28:40 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -26,9 +26,9 @@ | |||
26 | void luaD_init (lua_State *L, int stacksize); | 26 | void luaD_init (lua_State *L, int stacksize); |
27 | void luaD_adjusttop (lua_State *L, StkId base, int extra); | 27 | void luaD_adjusttop (lua_State *L, StkId base, int extra); |
28 | void luaD_openstack (lua_State *L, StkId pos); | 28 | void luaD_openstack (lua_State *L, StkId pos); |
29 | void luaD_callHook (lua_State *L, StkId func, lua_CHFunction callhook, | 29 | void luaD_callHook (lua_State *L, StkId func, lua_Dbghook callhook, |
30 | int isreturn); | 30 | const char *event); |
31 | void luaD_lineHook (lua_State *L, int line); | 31 | void luaD_lineHook (lua_State *L, StkId func, int line); |
32 | void luaD_call (lua_State *L, StkId func, int nResults); | 32 | void luaD_call (lua_State *L, StkId func, int nResults); |
33 | void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults); | 33 | void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults); |
34 | int luaD_protectedrun (lua_State *L); | 34 | int luaD_protectedrun (lua_State *L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.54 1999/12/28 11:52:49 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.55 1999/12/30 18:28:40 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -529,53 +529,49 @@ static void io_debug (lua_State *L) { | |||
529 | static void errorfb (lua_State *L) { | 529 | static void errorfb (lua_State *L) { |
530 | char buff[MAXMESSAGE]; | 530 | char buff[MAXMESSAGE]; |
531 | int level = 1; /* skip level 0 (it's this function) */ | 531 | int level = 1; /* skip level 0 (it's this function) */ |
532 | lua_Object func; | 532 | lua_Dbgactreg ar; |
533 | lua_Object alertfunc = lua_rawgetglobal(L, "_ALERT"); | ||
533 | sprintf(buff, "error: %.200s\n", lua_getstring(L, lua_getparam(L, 1))); | 534 | sprintf(buff, "error: %.200s\n", lua_getstring(L, lua_getparam(L, 1))); |
534 | while ((func = lua_stackedfunction(L, level++)) != LUA_NOOBJECT) { | 535 | while (lua_getstack(L, level++, &ar)) { |
535 | const char *name; | ||
536 | int currentline; | ||
537 | const char *chunkname; | ||
538 | char buffchunk[MAXSRC]; | 536 | char buffchunk[MAXSRC]; |
539 | int linedefined; | 537 | lua_getinfo(L, "Snl", &ar); |
540 | lua_funcinfo(L, func, &chunkname, &linedefined); | 538 | luaL_chunkid(buffchunk, ar.source, sizeof(buffchunk)); |
541 | luaL_chunkid(buffchunk, chunkname, sizeof(buffchunk)); | ||
542 | if (level == 2) strcat(buff, "Active Stack:\n"); | 539 | if (level == 2) strcat(buff, "Active Stack:\n"); |
543 | strcat(buff, " "); | 540 | strcat(buff, " "); |
544 | if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) { | 541 | if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) { |
545 | strcat(buff, "...\n"); | 542 | strcat(buff, "...\n"); |
546 | break; /* buffer is full */ | 543 | break; /* buffer is full */ |
547 | } | 544 | } |
548 | switch (*lua_getobjname(L, func, &name)) { | 545 | switch (*ar.namewhat) { |
549 | case 'g': case 'l': | 546 | case 'g': case 'l': /* global, local */ |
550 | sprintf(buff+strlen(buff), "function `%.50s'", name); | 547 | sprintf(buff+strlen(buff), "function `%.50s'", ar.name); |
551 | break; | 548 | break; |
552 | case 'f': | 549 | case 'f': /* field */ |
553 | sprintf(buff+strlen(buff), "method `%.50s'", name); | 550 | sprintf(buff+strlen(buff), "method `%.50s'", ar.name); |
554 | break; | 551 | break; |
555 | case 't': | 552 | case 't': /* tag method */ |
556 | sprintf(buff+strlen(buff), "`%.50s' tag method", name); | 553 | sprintf(buff+strlen(buff), "`%.50s' tag method", ar.name); |
557 | break; | 554 | break; |
558 | default: { | 555 | default: { |
559 | if (linedefined == 0) | 556 | if (*ar.what == 'm') /* main? */ |
560 | sprintf(buff+strlen(buff), "main of %.70s", buffchunk); | 557 | sprintf(buff+strlen(buff), "main of %.70s", buffchunk); |
561 | else if (linedefined < 0) | 558 | else if (*ar.what == 'C') /* C function? */ |
562 | sprintf(buff+strlen(buff), "%.70s", buffchunk); | 559 | sprintf(buff+strlen(buff), "%.70s", buffchunk); |
563 | else | 560 | else |
564 | sprintf(buff+strlen(buff), "function <%d:%.70s>", | 561 | sprintf(buff+strlen(buff), "function <%d:%.70s>", |
565 | linedefined, buffchunk); | 562 | ar.linedefined, buffchunk); |
566 | chunkname = NULL; | 563 | ar.source = NULL; |
567 | } | 564 | } |
568 | } | 565 | } |
569 | if ((currentline = lua_currentline(L, func)) > 0) | 566 | if (ar.currentline > 0) |
570 | sprintf(buff+strlen(buff), " at line %d", currentline); | 567 | sprintf(buff+strlen(buff), " at line %d", ar.currentline); |
571 | if (chunkname) | 568 | if (ar.source) |
572 | sprintf(buff+strlen(buff), " [%.70s]", buffchunk); | 569 | sprintf(buff+strlen(buff), " [%.70s]", buffchunk); |
573 | strcat(buff, "\n"); | 570 | strcat(buff, "\n"); |
574 | } | 571 | } |
575 | func = lua_rawgetglobal(L, "_ALERT"); | 572 | if (lua_isfunction(L, alertfunc)) { /* avoid loop if _ALERT is not defined */ |
576 | if (lua_isfunction(L, func)) { /* avoid error loop if _ALERT is not defined */ | ||
577 | lua_pushstring(L, buff); | 573 | lua_pushstring(L, buff); |
578 | lua_callfunction(L, func); | 574 | lua_callfunction(L, alertfunc); |
579 | } | 575 | } |
580 | } | 576 | } |
581 | 577 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 1.26 1999/12/21 18:04:41 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.27 1999/12/27 17:33:22 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -76,8 +76,8 @@ struct lua_State { | |||
76 | unsigned long GCthreshold; | 76 | unsigned long GCthreshold; |
77 | unsigned long nblocks; /* number of `blocks' currently allocated */ | 77 | unsigned long nblocks; /* number of `blocks' currently allocated */ |
78 | int debug; | 78 | int debug; |
79 | lua_CHFunction callhook; | 79 | lua_Dbghook callhook; |
80 | lua_LHFunction linehook; | 80 | lua_Dbghook linehook; |
81 | int allowhooks; | 81 | int allowhooks; |
82 | }; | 82 | }; |
83 | 83 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.3 1999/12/27 17:33:22 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.4 2000/01/13 16:30:47 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -230,10 +230,6 @@ static void testC (lua_State *L) { | |||
230 | int n = getreg(L, &pc); | 230 | int n = getreg(L, &pc); |
231 | lua_settagmethod(L, (int)lua_getnumber(L, reg[n]), getname(&pc)); | 231 | lua_settagmethod(L, (int)lua_getnumber(L, reg[n]), getname(&pc)); |
232 | } | 232 | } |
233 | else if EQ("getfunc") { | ||
234 | int n = getreg(L, &pc); | ||
235 | reg[n] = lua_stackedfunction(L, getnum(&pc)); | ||
236 | } | ||
237 | else if EQ("beginblock") { | 233 | else if EQ("beginblock") { |
238 | lua_beginblock(L); | 234 | lua_beginblock(L); |
239 | } | 235 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 1.29 1999/11/22 13:12:07 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.30 1999/12/23 18:19:57 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -108,8 +108,6 @@ int luaT_effectivetag (const TObject *o) { | |||
108 | LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, | 108 | LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, |
109 | LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, | 109 | LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, |
110 | LUA_T_LPROTO, LUA_T_CPROTO, /* LUA_T_LCLOSURE, LUA_T_CCLOSURE */ | 110 | LUA_T_LPROTO, LUA_T_CPROTO, /* LUA_T_LCLOSURE, LUA_T_CCLOSURE */ |
111 | LUA_T_LPROTO, LUA_T_CPROTO, /* LUA_T_LCLMARK, LUA_T_CCLMARK */ | ||
112 | LUA_T_LPROTO, LUA_T_CPROTO /* LUA_T_LMARK, LUA_T_CMARK */ | ||
113 | }; | 111 | }; |
114 | int t; | 112 | int t; |
115 | switch (t = ttype(o)) { | 113 | switch (t = ttype(o)) { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luadebug.h,v 1.7 1999/08/16 20:52:00 roberto Exp roberto $ | 2 | ** $Id: luadebug.h,v 1.8 1999/11/22 13:12:07 roberto Exp roberto $ |
3 | ** Debugging API | 3 | ** Debugging API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -11,25 +11,44 @@ | |||
11 | 11 | ||
12 | #include "lua.h" | 12 | #include "lua.h" |
13 | 13 | ||
14 | typedef lua_Object lua_Function; | 14 | typedef struct lua_Dbgactreg lua_Dbgactreg; /* activation record */ |
15 | typedef struct lua_Dbglocvar lua_Dbglocvar; /* local variable */ | ||
15 | 16 | ||
16 | typedef void (*lua_LHFunction) (lua_State *L, int line); | 17 | typedef void (*lua_Dbghook) (lua_State *L, lua_Dbgactreg *ar); |
17 | typedef void (*lua_CHFunction) (lua_State *L, lua_Function func, const char *file, int line); | ||
18 | 18 | ||
19 | lua_Function lua_stackedfunction (lua_State *L, int level); | ||
20 | void lua_funcinfo (lua_State *L, lua_Object func, const char **source, int *linedefined); | ||
21 | int lua_currentline (lua_State *L, lua_Function func); | ||
22 | const char *lua_getobjname (lua_State *L, lua_Object o, const char **name); | ||
23 | 19 | ||
24 | lua_Object lua_getlocal (lua_State *L, lua_Function func, int local_number, | 20 | int lua_getstack (lua_State *L, int level, lua_Dbgactreg *ar); |
25 | const char **name); | 21 | int lua_getinfo (lua_State *L, const char *what, lua_Dbgactreg *ar); |
26 | int lua_setlocal (lua_State *L, lua_Function func, int local_number); | 22 | int lua_getlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v); |
23 | int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v); | ||
27 | 24 | ||
28 | int lua_nups (lua_State *L, lua_Function func); | ||
29 | |||
30 | lua_LHFunction lua_setlinehook (lua_State *L, lua_LHFunction func); | ||
31 | lua_CHFunction lua_setcallhook (lua_State *L, lua_CHFunction func); | ||
32 | int lua_setdebug (lua_State *L, int debug); | 25 | int lua_setdebug (lua_State *L, int debug); |
33 | 26 | ||
27 | lua_Dbghook lua_setcallhook (lua_State *L, lua_Dbghook func); | ||
28 | lua_Dbghook lua_setlinehook (lua_State *L, lua_Dbghook func); | ||
29 | |||
30 | |||
31 | |||
32 | struct lua_Dbgactreg { | ||
33 | const char *event; /* `call', `return' */ | ||
34 | const char *source; /* (S) */ | ||
35 | int linedefined; /* (S) */ | ||
36 | const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ | ||
37 | int currentline; /* (l) */ | ||
38 | const char *name; /* (n) */ | ||
39 | const char *namewhat; /* (n) global, tag method, local, field */ | ||
40 | int nups; /* (u) number of upvalues */ | ||
41 | lua_Object func; /* (f) function being executed */ | ||
42 | /* private part */ | ||
43 | lua_Object _func; /* active function */ | ||
44 | }; | ||
45 | |||
46 | |||
47 | struct lua_Dbglocvar { | ||
48 | int index; | ||
49 | const char *name; | ||
50 | lua_Object value; | ||
51 | }; | ||
52 | |||
34 | 53 | ||
35 | #endif | 54 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.78 1999/12/30 18:28:40 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.79 2000/01/13 15:56:03 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -308,7 +308,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
308 | register const Byte *pc = tf->code; | 308 | register const Byte *pc = tf->code; |
309 | const TObject *consts = tf->consts; | 309 | const TObject *consts = tf->consts; |
310 | if (L->callhook) | 310 | if (L->callhook) |
311 | luaD_callHook(L, base-1, L->callhook, 0); | 311 | luaD_callHook(L, base-1, L->callhook, "call"); |
312 | luaD_checkstack(L, (*pc++)+EXTRA_STACK); | 312 | luaD_checkstack(L, (*pc++)+EXTRA_STACK); |
313 | if (*pc < ZEROVARARG) | 313 | if (*pc < ZEROVARARG) |
314 | luaD_adjusttop(L, base, *(pc++)); | 314 | luaD_adjusttop(L, base, *(pc++)); |
@@ -617,7 +617,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
617 | (base-2)->value.i = aux; | 617 | (base-2)->value.i = aux; |
618 | if (L->linehook) { | 618 | if (L->linehook) { |
619 | L->top = top; | 619 | L->top = top; |
620 | luaD_lineHook(L, aux); | 620 | luaD_lineHook(L, base-3, aux); |
621 | } | 621 | } |
622 | break; | 622 | break; |
623 | 623 | ||