lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 2bddbe660321547e606022f9c82e9511e54d5df6
parent e323338fd09216069d1290ec099ac987aadb036b
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Tue, 10 Oct 2000 17:51:17 -0200

cannot change `filename' before eventual call to `freopen'

Diffstat:
Mldo.c | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/ldo.c b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.105 2000/10/09 13:47:32 roberto Exp roberto $ +** $Id: ldo.c,v 1.106 2000/10/09 15:46:43 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -264,11 +264,6 @@ static int parse_file (lua_State *L, const char *filename) { int c; /* look ahead char */ FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); if (f == NULL) return LUA_ERRFILE; /* unable to open file */ - 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); @@ -276,6 +271,11 @@ 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 */ } + 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 */ luaZ_Fopen(&z, f, filename); status = protectedparser(L, &z, bin); if (f != stdin)