diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-03-10 11:19:41 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-03-10 11:19:41 -0300 |
commit | f2d35bdc7831dce6b1e9fcd639510bdc91488bc2 (patch) | |
tree | 6d0f085cf894f31605e52ad0ce2a1e11cea190f3 | |
parent | 26794616374fee54532d0030ae006abb77dfb7ba (diff) | |
download | lua-f2d35bdc7831dce6b1e9fcd639510bdc91488bc2.tar.gz lua-f2d35bdc7831dce6b1e9fcd639510bdc91488bc2.tar.bz2 lua-f2d35bdc7831dce6b1e9fcd639510bdc91488bc2.zip |
format for file source is independent of "ldo".
-rw-r--r-- | lauxlib.c | 9 | ||||
-rw-r--r-- | lauxlib.h | 4 | ||||
-rw-r--r-- | ldo.c | 11 |
3 files changed, 15 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.14 1999/02/25 19:13:56 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.15 1999/03/04 21:17:26 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -126,3 +126,10 @@ void luaL_chunkid (char *out, char *source, int len) { | |||
126 | } | 126 | } |
127 | } | 127 | } |
128 | 128 | ||
129 | |||
130 | void luaL_filesource (char *out, char *filename, int len) { | ||
131 | if (filename == NULL) | ||
132 | strcpy(out, "@(stdin)"); | ||
133 | else | ||
134 | sprintf(out, "@%.*s", len-2, filename); /* -2 for '@' and '\0' */ | ||
135 | } | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.h,v 1.10 1998/12/28 13:44:54 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.11 1999/03/04 21:17:26 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -47,5 +47,7 @@ void luaL_oldbuffer (int old); | |||
47 | char *luaL_buffer (void); | 47 | char *luaL_buffer (void); |
48 | int luaL_findstring (char *name, char *list[]); | 48 | int luaL_findstring (char *name, char *list[]); |
49 | void luaL_chunkid (char *out, char *source, int len); | 49 | void luaL_chunkid (char *out, char *source, int len); |
50 | void luaL_filesource (char *out, char *filename, int len); | ||
51 | |||
50 | 52 | ||
51 | #endif | 53 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.37 1999/03/04 21:17:26 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.38 1999/03/05 20:45:01 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 | */ |
@@ -362,20 +362,17 @@ int lua_dofile (char *filename) { | |||
362 | int status; | 362 | int status; |
363 | int c; | 363 | int c; |
364 | int bin; | 364 | int bin; |
365 | char name[MAXFILENAME+2]; /* +2 for '@' and '\0' */ | 365 | char source[MAXFILENAME]; |
366 | FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); | 366 | FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); |
367 | if (f == NULL) | 367 | if (f == NULL) |
368 | return 2; | 368 | return 2; |
369 | if (filename == NULL) | ||
370 | strcpy(name, "@(stdin)"); | ||
371 | else | ||
372 | sprintf(name, "@%.*s", MAXFILENAME, filename); | ||
373 | c = fgetc(f); | 369 | c = fgetc(f); |
374 | ungetc(c, f); | 370 | ungetc(c, f); |
375 | bin = (c == ID_CHUNK); | 371 | bin = (c == ID_CHUNK); |
376 | if (bin) | 372 | if (bin) |
377 | f = freopen(filename, "rb", f); /* set binary mode */ | 373 | f = freopen(filename, "rb", f); /* set binary mode */ |
378 | luaZ_Fopen(&z, f, name); | 374 | luaL_filesource(source, filename, MAXFILENAME); |
375 | luaZ_Fopen(&z, f, source); | ||
379 | status = do_main(&z, bin); | 376 | status = do_main(&z, bin); |
380 | if (f != stdin) | 377 | if (f != stdin) |
381 | fclose(f); | 378 | fclose(f); |