aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-09 11:47:32 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-09 11:47:32 -0200
commitd6232a0b2e53d6bd374c762a4f47e7a8799de5d2 (patch)
treeec882867b57b126f4f53fae5bd599768a2635408
parentae63a0e692fdc64a2bbafcb6ff10ecbdf3946f88 (diff)
downloadlua-d6232a0b2e53d6bd374c762a4f47e7a8799de5d2.tar.gz
lua-d6232a0b2e53d6bd374c762a4f47e7a8799de5d2.tar.bz2
lua-d6232a0b2e53d6bd374c762a4f47e7a8799de5d2.zip
better treatment for source names
-rw-r--r--ldebug.c4
-rw-r--r--ldo.c12
-rw-r--r--llimits.h10
-rw-r--r--lobject.c38
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 @@
1/* 1/*
2** $Id: ldebug.c,v 1.45 2000/10/05 13:00:17 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.46 2000/10/06 12:45:25 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -193,7 +193,7 @@ static void lua_funcinfo (lua_State *L, lua_Debug *ar, StkId func) {
193 lua_error(L, "value for `lua_getinfo' is not a function"); 193 lua_error(L, "value for `lua_getinfo' is not a function");
194 } 194 }
195 if (cl->isC) { 195 if (cl->isC) {
196 ar->source = "(C)"; 196 ar->source = "=C";
197 ar->linedefined = -1; 197 ar->linedefined = -1;
198 ar->what = "C"; 198 ar->what = "C";
199 } 199 }
diff --git a/ldo.c b/ldo.c
index a3752042..46d53d57 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.103 2000/10/05 13:00:17 roberto Exp roberto $ 2** $Id: ldo.c,v 1.104 2000/10/06 12:45:25 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -260,14 +260,16 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
260 260
261static int parse_file (lua_State *L, const char *filename) { 261static int parse_file (lua_State *L, const char *filename) {
262 ZIO z; 262 ZIO z;
263 char source[MAXFILENAME];
264 int status; 263 int status;
265 int bin; /* flag for file mode */ 264 int bin; /* flag for file mode */
266 int c; /* look ahead char */ 265 int c; /* look ahead char */
267 FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); 266 FILE *f = (filename == NULL) ? stdin : fopen(filename, "r");
268 if (f == NULL) return LUA_ERRFILE; /* unable to open file */ 267 if (f == NULL) return LUA_ERRFILE; /* unable to open file */
269 if (filename == NULL) filename = "(stdin)"; 268 lua_pushstring(L, "@");
270 sprintf(source, "@%.*s", (int)sizeof(source)-2, filename); 269 lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename);
270 lua_concat(L, 2);
271 filename = lua_tostring(L, -1); /* filename = '@'..filename */
272 lua_pop(L, 1); /* OK: there is no GC during parser */
271 c = fgetc(f); 273 c = fgetc(f);
272 ungetc(c, f); 274 ungetc(c, f);
273 bin = (c == ID_CHUNK); 275 bin = (c == ID_CHUNK);
@@ -275,7 +277,7 @@ static int parse_file (lua_State *L, const char *filename) {
275 f = freopen(filename, "rb", f); /* set binary mode */ 277 f = freopen(filename, "rb", f); /* set binary mode */
276 if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ 278 if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */
277 } 279 }
278 luaZ_Fopen(&z, f, source); 280 luaZ_Fopen(&z, f, filename);
279 status = protectedparser(L, &z, bin); 281 status = protectedparser(L, &z, bin);
280 if (f != stdin) 282 if (f != stdin)
281 fclose(f); 283 fclose(f);
diff --git a/llimits.h b/llimits.h
index 3a56d97e..8c0c1b48 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.16 2000/10/03 14:03:21 roberto Exp roberto $ 2** $Id: llimits.h,v 1.17 2000/10/06 19:28:38 roberto Exp roberto $
3** Limits, basic types, and some other "installation-dependent" definitions 3** Limits, basic types, and some other "installation-dependent" definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -104,7 +104,7 @@ typedef unsigned long Instruction;
104/* 104/*
105** limits for opcode arguments. 105** limits for opcode arguments.
106** we use (signed) int to manipulate most arguments, 106** we use (signed) int to manipulate most arguments,
107** so they must fit in BITS_INT-1 bits (-1 for signal) 107** so they must fit in BITS_INT-1 bits (-1 for sign)
108*/ 108*/
109#if SIZE_U < BITS_INT-1 109#if SIZE_U < BITS_INT-1
110#define MAXARG_U ((1<<SIZE_U)-1) 110#define MAXARG_U ((1<<SIZE_U)-1)
@@ -196,10 +196,4 @@ typedef unsigned long Instruction;
196#endif 196#endif
197 197
198 198
199/* maximum part of a file name kept for error messages */
200#ifndef MAXFILENAME
201#define MAXFILENAME 260
202#endif
203
204
205#endif 199#endif
diff --git a/lobject.c b/lobject.c
index de79dcdc..4c06bf72 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.51 2000/10/03 14:03:21 roberto Exp roberto $ 2** $Id: lobject.c,v 1.52 2000/10/05 12:14:08 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -87,23 +87,31 @@ void luaO_verror (lua_State *L, const char *fmt, ...) {
87} 87}
88 88
89 89
90#define EXTRALEN sizeof("string \"...\"0") 90#define EXTRALEN sizeof(" string \"s...\" ")
91 91
92void luaO_chunkid (char *out, const char *source, int len) { 92void luaO_chunkid (char *out, const char *source, int bufflen) {
93 if (*source == '(') { 93 if (*source == '=')
94 strncpy(out, source+1, len-1); /* remove first char */ 94 sprintf(out, "%.*s", bufflen, source+1); /* remove first char */
95 out[len-1] = '\0'; /* make sure `out' has an end */
96 out[strlen(out)-1] = '\0'; /* remove last char */
97 }
98 else { 95 else {
99 len -= EXTRALEN; 96 bufflen -= EXTRALEN;
100 if (*source == '@') 97 if (*source == '@') {
101 sprintf(out, "file `%.*s'", len, source+1); 98 int l;
99 source++; /* skip the `@' */
100 l = strlen(source);
101 if (l>bufflen) {
102 source += (l-bufflen); /* get last part of file name */
103 sprintf(out, "file `...%s'", source);
104 }
105 else
106 sprintf(out, "file `%s'", source);
107 }
102 else { 108 else {
103 const char *b = strchr(source , '\n'); /* stop at first new line */ 109 int len = strcspn(source, "\n"); /* stop at first newline */
104 int lim = (b && (b-source)<len) ? b-source : len; 110 if (len > bufflen) len = bufflen;
105 sprintf(out, "string \"%.*s\"", lim, source); 111 if (source[len] != '\0') /* must truncate? */
106 strcpy(out+lim+(EXTRALEN-sizeof("...\"0")), "...\""); 112 sprintf(out, "string \"%.*s...\"", len, source);
113 else
114 sprintf(out, "string \"%s\"", source);
107 } 115 }
108 } 116 }
109} 117}