aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-12-02 11:19:03 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-12-02 11:19:03 -0300
commit04e495403ba66e88abfb5cc4cf1887f094eea57f (patch)
tree6054afd488012323412027fad6d8f5c74771e1c2 /ltests.c
parent62afbc6bfce222ebe745863131f952f6fce5eafb (diff)
downloadlua-04e495403ba66e88abfb5cc4cf1887f094eea57f.tar.gz
lua-04e495403ba66e88abfb5cc4cf1887f094eea57f.tar.bz2
lua-04e495403ba66e88abfb5cc4cf1887f094eea57f.zip
New function 'lua_printvalue' for internal debugging
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/ltests.c b/ltests.c
index 44ed7bcc..6c77703c 100644
--- a/ltests.c
+++ b/ltests.c
@@ -325,6 +325,37 @@ void lua_printobj (lua_State *L, struct GCObject *o) {
325 printobj(G(L), o); 325 printobj(G(L), o);
326} 326}
327 327
328
329void lua_printvalue (TValue *v) {
330 switch (ttype(v)) {
331 case LUA_TNUMBER: {
332 char buff[LUA_N2SBUFFSZ];
333 unsigned len = luaO_tostringbuff(v, buff);
334 buff[len] = '\0';
335 printf("%s", buff);
336 break;
337 }
338 case LUA_TSTRING: {
339 printf("'%s'", getstr(tsvalue(v)));
340 break;
341 }
342 case LUA_TBOOLEAN: {
343 printf("%s", (!l_isfalse(v) ? "true" : "false"));
344 break;
345 }
346 case LUA_TNIL: {
347 printf("nil");
348 break;
349 }
350 default: {
351 void *p = iscollectable(v) ? gcvalue(v) : NULL;
352 printf("%s: %p", ttypename(ttype(v)), p);
353 break;
354 }
355 }
356}
357
358
328static int testobjref (global_State *g, GCObject *f, GCObject *t) { 359static int testobjref (global_State *g, GCObject *f, GCObject *t) {
329 int r1 = testobjref1(g, f, t); 360 int r1 = testobjref1(g, f, t);
330 if (!r1) { 361 if (!r1) {
@@ -827,8 +858,9 @@ void lua_printstack (lua_State *L) {
827 int n = lua_gettop(L); 858 int n = lua_gettop(L);
828 printf("stack: >>\n"); 859 printf("stack: >>\n");
829 for (i = 1; i <= n; i++) { 860 for (i = 1; i <= n; i++) {
830 printf("%3d: %s\n", i, luaL_tolstring(L, i, NULL)); 861 printf("%3d: ", i);
831 lua_pop(L, 1); 862 lua_printvalue(s2v(L->ci->func.p + i));
863 printf("\n");
832 } 864 }
833 printf("<<\n"); 865 printf("<<\n");
834} 866}
@@ -1681,8 +1713,8 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
1681 else if EQ("printstack") { 1713 else if EQ("printstack") {
1682 int n = getnum; 1714 int n = getnum;
1683 if (n != 0) { 1715 if (n != 0) {
1684 printf("%s\n", luaL_tolstring(L1, n, NULL)); 1716 lua_printvalue(s2v(L->ci->func.p + n));
1685 lua_pop(L1, 1); 1717 printf("\n");
1686 } 1718 }
1687 else lua_printstack(L1); 1719 else lua_printstack(L1);
1688 } 1720 }