diff options
| -rw-r--r-- | lauxlib.c | 16 |
1 files changed, 2 insertions, 14 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.196 2009/12/22 15:32:50 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.197 2010/01/21 16:49:21 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 | */ |
| @@ -495,7 +495,6 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { | |||
| 495 | */ | 495 | */ |
| 496 | 496 | ||
| 497 | typedef struct LoadF { | 497 | typedef struct LoadF { |
| 498 | int extraline; | ||
| 499 | FILE *f; | 498 | FILE *f; |
| 500 | char buff[LUAL_BUFFERSIZE]; | 499 | char buff[LUAL_BUFFERSIZE]; |
| 501 | } LoadF; | 500 | } LoadF; |
| @@ -504,11 +503,6 @@ typedef struct LoadF { | |||
| 504 | static const char *getF (lua_State *L, void *ud, size_t *size) { | 503 | static const char *getF (lua_State *L, void *ud, size_t *size) { |
| 505 | LoadF *lf = (LoadF *)ud; | 504 | LoadF *lf = (LoadF *)ud; |
| 506 | (void)L; | 505 | (void)L; |
| 507 | if (lf->extraline) { | ||
| 508 | lf->extraline = 0; | ||
| 509 | *size = 1; | ||
| 510 | return "\n"; | ||
| 511 | } | ||
| 512 | /* 'fread' can return > 0 *and* set the EOF flag. If next call to | 506 | /* 'fread' can return > 0 *and* set the EOF flag. If next call to |
| 513 | 'getF' calls 'fread', terminal may still wait for user input. | 507 | 'getF' calls 'fread', terminal may still wait for user input. |
| 514 | The next check avoids this problem. */ | 508 | The next check avoids this problem. */ |
| @@ -532,7 +526,6 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { | |||
| 532 | int status, readstatus; | 526 | int status, readstatus; |
| 533 | int c; | 527 | int c; |
| 534 | int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ | 528 | int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ |
| 535 | lf.extraline = 0; | ||
| 536 | if (filename == NULL) { | 529 | if (filename == NULL) { |
| 537 | lua_pushliteral(L, "=stdin"); | 530 | lua_pushliteral(L, "=stdin"); |
| 538 | lf.f = stdin; | 531 | lf.f = stdin; |
| @@ -544,16 +537,11 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { | |||
| 544 | } | 537 | } |
| 545 | c = getc(lf.f); | 538 | c = getc(lf.f); |
| 546 | if (c == '#') { /* Unix exec. file? */ | 539 | if (c == '#') { /* Unix exec. file? */ |
| 547 | lf.extraline = 1; | ||
| 548 | while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ | 540 | while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ |
| 549 | if (c == '\n') c = getc(lf.f); | ||
| 550 | } | 541 | } |
| 551 | if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ | 542 | else if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ |
| 552 | lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ | 543 | lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ |
| 553 | if (lf.f == NULL) return errfile(L, "reopen", fnameindex); | 544 | if (lf.f == NULL) return errfile(L, "reopen", fnameindex); |
| 554 | /* skip eventual `#!...' */ | ||
| 555 | while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; | ||
| 556 | lf.extraline = 0; | ||
| 557 | } | 545 | } |
| 558 | ungetc(c, lf.f); | 546 | ungetc(c, lf.f); |
| 559 | status = lua_load(L, getF, &lf, lua_tostring(L, -1)); | 547 | status = lua_load(L, getF, &lf, lua_tostring(L, -1)); |
