diff options
| -rw-r--r-- | ldo.c | 6 |
1 files changed, 4 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.131 2001/03/07 18:09:25 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.132 2001/03/26 14:31:49 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 | */ |
| @@ -259,6 +259,7 @@ static int parse_file (lua_State *L, const l_char *filename) { | |||
| 259 | ZIO z; | 259 | ZIO z; |
| 260 | int status; | 260 | int status; |
| 261 | int bin; /* flag for file mode */ | 261 | int bin; /* flag for file mode */ |
| 262 | int nlevel; /* level on the stack of filename */ | ||
| 262 | FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r")); | 263 | FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r")); |
| 263 | if (f == NULL) return LUA_ERRFILE; /* unable to open file */ | 264 | if (f == NULL) return LUA_ERRFILE; /* unable to open file */ |
| 264 | bin = (ungetc(fgetc(f), f) == ID_CHUNK); | 265 | bin = (ungetc(fgetc(f), f) == ID_CHUNK); |
| @@ -270,10 +271,11 @@ static int parse_file (lua_State *L, const l_char *filename) { | |||
| 270 | lua_pushliteral(L, l_s("@")); | 271 | lua_pushliteral(L, l_s("@")); |
| 271 | lua_pushstring(L, (filename == NULL) ? l_s("(stdin)") : filename); | 272 | lua_pushstring(L, (filename == NULL) ? l_s("(stdin)") : filename); |
| 272 | lua_concat(L, 2); | 273 | lua_concat(L, 2); |
| 274 | nlevel = lua_gettop(L); | ||
| 273 | filename = lua_tostring(L, -1); /* filename = `@'..filename */ | 275 | filename = lua_tostring(L, -1); /* filename = `@'..filename */ |
| 274 | luaZ_Fopen(&z, f, filename); | 276 | luaZ_Fopen(&z, f, filename); |
| 275 | status = protectedparser(L, &z, bin); | 277 | status = protectedparser(L, &z, bin); |
| 276 | lua_remove(L, -2); /* remove filename */ | 278 | lua_remove(L, nlevel); /* remove filename */ |
| 277 | if (f != stdin) | 279 | if (f != stdin) |
| 278 | fclose(f); | 280 | fclose(f); |
| 279 | return status; | 281 | return status; |
