From d6232a0b2e53d6bd374c762a4f47e7a8799de5d2 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 9 Oct 2000 11:47:32 -0200 Subject: better treatment for source names --- ldebug.c | 4 ++-- ldo.c | 12 +++++++----- llimits.h | 10 ++-------- lobject.c | 38 +++++++++++++++++++++++--------------- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/ldebug.c b/ldebug.c index 1aff2064..04e81ac4 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 1.45 2000/10/05 13:00:17 roberto Exp roberto $ +** $Id: ldebug.c,v 1.46 2000/10/06 12:45:25 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -193,7 +193,7 @@ static void lua_funcinfo (lua_State *L, lua_Debug *ar, StkId func) { lua_error(L, "value for `lua_getinfo' is not a function"); } if (cl->isC) { - ar->source = "(C)"; + ar->source = "=C"; ar->linedefined = -1; ar->what = "C"; } diff --git a/ldo.c b/ldo.c index a3752042..46d53d57 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.103 2000/10/05 13:00:17 roberto Exp roberto $ +** $Id: ldo.c,v 1.104 2000/10/06 12:45:25 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -260,14 +260,16 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { static int parse_file (lua_State *L, const char *filename) { ZIO z; - char source[MAXFILENAME]; int status; int bin; /* flag for file mode */ int c; /* look ahead char */ FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); if (f == NULL) return LUA_ERRFILE; /* unable to open file */ - if (filename == NULL) filename = "(stdin)"; - sprintf(source, "@%.*s", (int)sizeof(source)-2, filename); + lua_pushstring(L, "@"); + lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename); + lua_concat(L, 2); + filename = lua_tostring(L, -1); /* filename = '@'..filename */ + lua_pop(L, 1); /* OK: there is no GC during parser */ c = fgetc(f); ungetc(c, f); bin = (c == ID_CHUNK); @@ -275,7 +277,7 @@ static int parse_file (lua_State *L, const char *filename) { f = freopen(filename, "rb", f); /* set binary mode */ if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ } - luaZ_Fopen(&z, f, source); + luaZ_Fopen(&z, f, filename); status = protectedparser(L, &z, bin); if (f != stdin) fclose(f); diff --git a/llimits.h b/llimits.h index 3a56d97e..8c0c1b48 100644 --- a/llimits.h +++ b/llimits.h @@ -1,5 +1,5 @@ /* -** $Id: llimits.h,v 1.16 2000/10/03 14:03:21 roberto Exp roberto $ +** $Id: llimits.h,v 1.17 2000/10/06 19:28:38 roberto Exp roberto $ ** Limits, basic types, and some other "installation-dependent" definitions ** See Copyright Notice in lua.h */ @@ -104,7 +104,7 @@ typedef unsigned long Instruction; /* ** limits for opcode arguments. ** we use (signed) int to manipulate most arguments, -** so they must fit in BITS_INT-1 bits (-1 for signal) +** so they must fit in BITS_INT-1 bits (-1 for sign) */ #if SIZE_U < BITS_INT-1 #define MAXARG_U ((1<bufflen) { + source += (l-bufflen); /* get last part of file name */ + sprintf(out, "file `...%s'", source); + } + else + sprintf(out, "file `%s'", source); + } else { - const char *b = strchr(source , '\n'); /* stop at first new line */ - int lim = (b && (b-source) bufflen) len = bufflen; + if (source[len] != '\0') /* must truncate? */ + sprintf(out, "string \"%.*s...\"", len, source); + else + sprintf(out, "string \"%s\"", source); } } } -- cgit v1.2.3-55-g6feb