Browse Source

new module luadebug.h.

Roberto Ierusalimschy 30 years ago
parent
commit
d80659759b
4 changed files with 42 additions and 10 deletions
  1. 31 2
      iolib.c
  2. 3 1
      lua.h
  3. 4 4
      makefile
  4. 4 3
      opcode.c

+ 31 - 2
iolib.c

@@ -3,7 +3,7 @@
 ** Input/output library to LUA
 */
 
-char *rcs_iolib="$Id: iolib.c,v 1.22 1995/10/04 13:53:10 roberto Exp roberto $";
+char *rcs_iolib="$Id: iolib.c,v 1.23 1995/10/11 20:50:56 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <ctype.h>
@@ -14,6 +14,7 @@ char *rcs_iolib="$Id: iolib.c,v 1.22 1995/10/04 13:53:10 roberto Exp roberto $";
 #include <stdlib.h>
 
 #include "lua.h"
+#include "luadebug.h"
 #include "lualib.h"
 
 static FILE *in=stdin, *out=stdout;
@@ -580,7 +581,7 @@ static void io_exit (void)
 {
  lua_Object o = lua_getparam(1);
  if (lua_isstring(o))
-  printf("%s\n", lua_getstring(o));
+  fprintf(stderr, "%s\n", lua_getstring(o));
  exit(1);
 }
 
@@ -600,6 +601,33 @@ static void io_debug (void)
   }
 }
 
+
+static void print_message (void)
+{
+  lua_Object o = lua_getparam(1);
+  char *s = lua_isstring(o) ? lua_getstring(o) : "(no messsage)";
+  int level = 0;
+  lua_Object func;
+  fprintf(stderr, "lua: %s\n", s);
+  fprintf(stderr, "Active Stack:\n");
+  while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT)
+  {
+    char *filename; char *funcname;
+    char *objname; int linedefined;
+    lua_funcinfo(func, &filename, &funcname, &objname, &linedefined);
+    if (objname == NULL)
+      if (funcname)
+        fprintf(stderr, "\t%s\n", funcname);
+      else
+      {
+        fprintf(stderr, "\tmain of %s\n", filename);
+      }
+    else
+      fprintf(stderr, "\t%s:%s\n", objname, funcname);
+/*    fprintf(stderr, "\t(in file: %s)\n", filename); */
+  }
+}
+
 /*
 ** Open io library
 */
@@ -619,4 +647,5 @@ void iolib_open (void)
  lua_register ("beep",     io_beep);
  lua_register ("exit",     io_exit);
  lua_register ("debug",    io_debug);
+ lua_setfallback("error", print_message);
 }

+ 3 - 1
lua.h

@@ -2,7 +2,7 @@
 ** LUA - Linguagem para Usuarios de Aplicacao
 ** Grupo de Tecnologia em Computacao Grafica
 ** TeCGraf - PUC-Rio
-** $Id: lua.h,v 3.16 1995/01/27 17:19:06 celes Exp roberto $
+** $Id: lua.h,v 3.17 1995/10/06 14:11:10 roberto Exp roberto $
 */
 
 
@@ -24,6 +24,8 @@ typedef enum
  LUA_T_ARRAY	= -4,
  LUA_T_FUNCTION	= -5,
  LUA_T_CFUNCTION= -6,
+ LUA_T_MARK	= -7,
+ LUA_T_CMARK	= -8,
  LUA_T_USERDATA = 0
 } lua_Type;
  

+ 4 - 4
makefile

@@ -1,4 +1,4 @@
-# $Id: makefile,v 1.13 1995/10/04 19:19:46 roberto Exp roberto $
+# $Id: makefile,v 1.13 1995/10/09 18:51:49 roberto Exp roberto $
 
 #configuration
 
@@ -61,7 +61,7 @@ clear	:
 	rcsclean
 	rm -f *.o
 	rm -f parser.c parser.h
-	co lua.h lualib.h
+	co lua.h lualib.h luadebug.h
 
 % : RCS/%,v
 	co $@
@@ -72,14 +72,14 @@ func.o : func.c table.h tree.h types.h opcode.h lua.h func.h mem.h
 hash.o : hash.c mem.h opcode.h lua.h types.h tree.h func.h hash.h table.h 
 inout.o : inout.c mem.h opcode.h lua.h types.h tree.h func.h hash.h inout.h \
   table.h 
-iolib.o : iolib.c lua.h lualib.h 
+iolib.o : iolib.c lua.h lualib.h luadebug.h
 lex.o : lex.c mem.h tree.h types.h table.h opcode.h lua.h func.h inout.h parser.h \
   ugly.h 
 lua.o : lua.c lua.h lualib.h 
 mathlib.o : mathlib.c lualib.h lua.h 
 mem.o : mem.c mem.h lua.h 
 opcode.o : opcode.c mem.h opcode.h lua.h types.h tree.h func.h hash.h inout.h \
-  table.h fallback.h 
+  table.h fallback.h luadebug.h
 parser.o : parser.c mem.h opcode.h lua.h types.h tree.h func.h hash.h inout.h \
   table.h 
 strlib.o : strlib.c lua.h lualib.h 

+ 4 - 3
opcode.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
 
-char *rcs_opcode="$Id: opcode.c,v 3.43 1995/10/13 15:16:25 roberto Exp roberto $";
+char *rcs_opcode="$Id: opcode.c,v 3.44 1995/10/17 11:58:41 roberto Exp roberto $";
 
 #include <setjmp.h>
 #include <stdlib.h>
@@ -11,6 +11,7 @@ char *rcs_opcode="$Id: opcode.c,v 3.43 1995/10/13 15:16:25 roberto Exp roberto $
 #include <string.h>
 #include <math.h>
 
+#include "luadebug.h"
 #include "mem.h"
 #include "opcode.h"
 #include "hash.h"
@@ -353,7 +354,7 @@ void lua_error (char *s)
 }
 
 
-lua_Object luaD_stackedfunction (int level)
+lua_Object lua_stackedfunction (int level)
 {
   Object *p = top;
   while (--p >= stack)
@@ -364,7 +365,7 @@ lua_Object luaD_stackedfunction (int level)
 }
 
 
-void luaD_funcInfo (lua_Object func, char **filename, char **funcname,
+void lua_funcinfo (lua_Object func, char **filename, char **funcname,
                     char **objname, int *linedefined)
 {
   return luaI_funcInfo(Address(func), filename, funcname, objname, linedefined);