lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

  Just to make things clearer: below is a list of all "printf" inside Lua 3.1:

  lbuiltin.c:    printf("%s\t", svalue(L->;
  lbuiltin.c:  printf("\n");
  ldo.c:  fprintf(stderr, "lua error: %s\n", lua_getstring(lua_getparam(1)));
  ldo.c:    fprintf (stderr, "lua: exit(1). Unable to recover\n");
* liolib.c:    fprintf(stderr, "lua_debug> ");
* liolib.c:    fprintf(f, (level==2) ? "Active Stack:\n\t" : "\t");
* liolib.c:        fprintf(f, "function %s", name);
* liolib.c:        fprintf(f, "`%s' tag method", name);
* liolib.c:          fprintf(f, "main of %s", filename);
* liolib.c:          fprintf(f, "%s", filename);
* liolib.c:          fprintf(f, "function (%s:%d)", filename, linedefined);
* liolib.c:      fprintf(f, " at line %d", currentline);
* liolib.c:      fprintf(f, " [in file %s]", filename);
* liolib.c:    fprintf(f, "\n");
* liolib.c:  fprintf(stderr, "lua: %s\n", lua_getstring(lua_getparam(1)));
- lstate.c:  printf("total de blocos: %ld\n", numblocks);
- lstate.c:  printf("total de memoria: %ld\n", totalmem);
  ltm.c:    fprintf(stderr, "lua: %s\n", lua_getstring(o));
  ltm.c:    fprintf(stderr, "lua: unknown error\n");
+ lua.c:  fprintf(stderr,
+ lua.c:    fprintf(stderr, "lua: shell argument too long");
+ lua.c:      printf("%s", lua_getstring(lua_getglobal("_PROMPT")));
+ lua.c:        fprintf(stderr, "lua: argument line too long\n");
+ lua.c:  printf("\n");
+ lua.c:      printf("%s  %s\n", LUA_VERSION, LUA_COPYRIGHT);
+ lua.c:          printf("%s  %s\n(written by %s)\n\n",
+ lua.c:            fprintf(stderr, "lua: error running argument `%s'\n", argv[i]);
+ lua.c:          fprintf(stderr, "lua: cannot execute file ");

Those with * are part of the standard input/output library, which explicitly
uses streams. + is the stand-alone Lua, which needs a console. - is just for
debuging (the messages are in Portuguese ;-). (In fact, there are also a
few "getc", but again they only appear in the I/O library and the
stand-alone program.) That leave us with:

1 lbuiltin.c:    printf("%s\t", svalue(L->;
2 lbuiltin.c:  printf("\n");
3 ldo.c:  fprintf(stderr, "lua error: %s\n", lua_getstring(lua_getparam(1)));
4 ldo.c:    fprintf (stderr, "lua: exit(1). Unable to recover\n");
5 ltm.c:    fprintf(stderr, "lua: %s\n", lua_getstring(o));
6 ltm.c:    fprintf(stderr, "lua: unknown error\n");

Lines 1/2 are the implementation of "print"; just redefine "print" to avoid
them. Lines 5/6 is the old implementation of the default error fallback, and 
line 3 is the current implementation of the default error handler; just
redefine the error handler to avoid them. That leave us with only line 4.
This is the only place in the core of Lua where you cannot avoid the use of
stderr, but this is an emergency exit (it is followed by an "exit"!). This
only happens if a Lua error occurs in a point when there is no point to
recover; that is, outside any dofile, dostring, or lua_call. It can only
happen in C, and independently of printf problems, you should always avoid
the chance of such errors.

  People here at PUC have been using Lua with Windows since its first version,
and this redefinition of "print" and the error handler have done the job,
so far. But maybe we are missing something.

  Anyway, we are afraid we won't be able to make any changes to 3.1. As lhf
said, it is practically ready (it is already frozen in the RCS, we are just
making some final tests in different platforms and building the "tar"), and
unless a real bug appears we will not change this version. But we can make
the change in the next version.

-- Roberto