|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
-** $Id: ldo.c,v 1.62 1999/12/29 16:31:15 roberto Exp roberto $
|
|
|
+** $Id: ldo.c,v 1.63 1999/12/30 18:28:40 roberto Exp roberto $
|
|
|
** Stack and Call structure of Lua
|
|
|
** See Copyright Notice in lua.h
|
|
|
*/
|
|
@@ -365,18 +365,26 @@ void luaD_gcIM (lua_State *L, const TObject *o) {
|
|
|
int lua_dofile (lua_State *L, const char *filename) {
|
|
|
ZIO z;
|
|
|
int status;
|
|
|
- int c;
|
|
|
int bin;
|
|
|
char source[MAXFILENAME];
|
|
|
- FILE *f = (filename == NULL) ? stdin : fopen(filename, "r");
|
|
|
- if (f == NULL)
|
|
|
- return 2;
|
|
|
- c = fgetc(f);
|
|
|
- ungetc(c, f);
|
|
|
- bin = (c == ID_CHUNK);
|
|
|
- if (bin)
|
|
|
- f = freopen(filename, "rb", f); /* set binary mode */
|
|
|
+ FILE *f;
|
|
|
luaL_filesource(source, filename, sizeof(source));
|
|
|
+ if (filename == NULL) {
|
|
|
+ f = stdin;
|
|
|
+ bin = 0; /* cannot handle stdin as a binary file */
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ int c;
|
|
|
+ f = fopen(filename, "r");
|
|
|
+ if (f == NULL) return 2; /* unable to open file */
|
|
|
+ c = fgetc(f);
|
|
|
+ ungetc(c, f);
|
|
|
+ bin = (c == ID_CHUNK);
|
|
|
+ if (bin) {
|
|
|
+ f = freopen(filename, "rb", f); /* set binary mode */
|
|
|
+ if (f == NULL) return 2; /* unable to reopen file */
|
|
|
+ }
|
|
|
+ }
|
|
|
luaZ_Fopen(&z, f, source);
|
|
|
status = do_main(L, &z, bin);
|
|
|
if (f != stdin)
|