diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-09 11:47:32 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-09 11:47:32 -0200 |
| commit | d6232a0b2e53d6bd374c762a4f47e7a8799de5d2 (patch) | |
| tree | ec882867b57b126f4f53fae5bd599768a2635408 /ldo.c | |
| parent | ae63a0e692fdc64a2bbafcb6ff10ecbdf3946f88 (diff) | |
| download | lua-d6232a0b2e53d6bd374c762a4f47e7a8799de5d2.tar.gz lua-d6232a0b2e53d6bd374c762a4f47e7a8799de5d2.tar.bz2 lua-d6232a0b2e53d6bd374c762a4f47e7a8799de5d2.zip | |
better treatment for source names
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 12 |
1 files changed, 7 insertions, 5 deletions
| @@ -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 | ||
| 261 | static int parse_file (lua_State *L, const char *filename) { | 261 | static 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); |
