moved source files to src directory
[wmiirc-lua.git] / src / luaixp / lixp_debug.c
blob8c8aec563a3fb13582b216e4c306545877be3abd
1 #include <stdio.h>
2 #include <lua.h>
3 #include <lauxlib.h>
5 #include "lixp_debug.h"
7 void
8 l_stack_dump (lua_State *l)
10 int i, rc;
11 int top = lua_gettop(l);
12 char buf[1024], *p;
13 char *e = buf+sizeof(buf);
15 fflush (stdout);
16 fprintf (stderr, "--- stack ---\n");
18 p = buf;
19 *buf = 0;
20 for (i = 1; i <= top; i++) { /* repeat for each level */
21 int t = lua_type(l, i);
22 switch (t) {
24 case LUA_TNIL: /* nothing */
25 p += rc = snprintf (p, e - p, " NIL");
26 if (rc<0) break;
27 break;
29 case LUA_TSTRING: /* strings */
30 p += rc = snprintf (p, e - p, " `%s'",
31 lua_tostring(l, i));
32 if (rc<0) break;
33 break;
35 case LUA_TBOOLEAN: /* booleans */
36 p += rc = snprintf (p, e-p,
37 lua_toboolean(l, i) ? "true" : "false");
38 if (rc<0) break;
39 break;
41 case LUA_TNUMBER: /* numbers */
42 p += rc = snprintf (p, e-p, " %g",
43 lua_tonumber(l, i));
44 if (rc<0) break;
45 break;
47 case LUA_TTABLE: /* table */
48 p += rc = snprintf (p, e-p, " table");
49 if (rc<0) break;
50 break;
52 default: /* other values */
53 p += rc = snprintf (p, e-p, " %s",
54 lua_typename(l, t));
55 if (rc<0) break;
56 break;
60 fprintf (stderr, "%s\n", buf); /* end the listing */
62 fprintf (stderr, "-------------\n");