diff options
| -rw-r--r-- | lauxlib.c | 24 |
1 files changed, 9 insertions, 15 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.164 2006/10/16 14:38:38 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.165 2007/02/07 17:51: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 | */ |
| @@ -234,21 +234,17 @@ LUALIB_API const char *luaL_tostring (lua_State *L, int idx) { | |||
| 234 | if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ | 234 | if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ |
| 235 | switch (lua_type(L, idx)) { | 235 | switch (lua_type(L, idx)) { |
| 236 | case LUA_TNUMBER: | 236 | case LUA_TNUMBER: |
| 237 | lua_pushstring(L, lua_tostring(L, idx)); | 237 | return lua_pushstring(L, lua_tostring(L, idx)); |
| 238 | break; | ||
| 239 | case LUA_TSTRING: | 238 | case LUA_TSTRING: |
| 240 | lua_pushvalue(L, idx); | 239 | lua_pushvalue(L, idx); |
| 241 | break; | 240 | break; |
| 242 | case LUA_TBOOLEAN: | 241 | case LUA_TBOOLEAN: |
| 243 | lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); | 242 | return lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); |
| 244 | break; | ||
| 245 | case LUA_TNIL: | 243 | case LUA_TNIL: |
| 246 | lua_pushliteral(L, "nil"); | 244 | return lua_pushliteral(L, "nil"); |
| 247 | break; | ||
| 248 | default: | 245 | default: |
| 249 | lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), | 246 | return lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), |
| 250 | lua_topointer(L, idx)); | 247 | lua_topointer(L, idx)); |
| 251 | break; | ||
| 252 | } | 248 | } |
| 253 | } | 249 | } |
| 254 | return lua_tostring(L, -1); | 250 | return lua_tostring(L, -1); |
| @@ -601,9 +597,8 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { | |||
| 601 | while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ | 597 | while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ |
| 602 | if (c == '\n') c = getc(lf.f); | 598 | if (c == '\n') c = getc(lf.f); |
| 603 | } | 599 | } |
| 604 | if (c == LUA_SIGNATURE[0] && lf.f != stdin) { /* binary file? */ | 600 | if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ |
| 605 | fclose(lf.f); | 601 | lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ |
| 606 | lf.f = fopen(filename, "rb"); /* reopen in binary mode */ | ||
| 607 | if (lf.f == NULL) return errfile(L, "reopen", fnameindex); | 602 | if (lf.f == NULL) return errfile(L, "reopen", fnameindex); |
| 608 | /* skip eventual `#!...' */ | 603 | /* skip eventual `#!...' */ |
| 609 | while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; | 604 | while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; |
| @@ -612,7 +607,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { | |||
| 612 | ungetc(c, lf.f); | 607 | ungetc(c, lf.f); |
| 613 | status = lua_load(L, getF, &lf, lua_tostring(L, -1)); | 608 | status = lua_load(L, getF, &lf, lua_tostring(L, -1)); |
| 614 | readstatus = ferror(lf.f); | 609 | readstatus = ferror(lf.f); |
| 615 | if (lf.f != stdin) fclose(lf.f); /* close file (even in case of errors) */ | 610 | if (filename) fclose(lf.f); /* close file (even in case of errors) */ |
| 616 | if (readstatus) { | 611 | if (readstatus) { |
| 617 | lua_settop(L, fnameindex); /* ignore results from `lua_load' */ | 612 | lua_settop(L, fnameindex); /* ignore results from `lua_load' */ |
| 618 | return errfile(L, "read", fnameindex); | 613 | return errfile(L, "read", fnameindex); |
| @@ -669,7 +664,6 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { | |||
| 669 | 664 | ||
| 670 | 665 | ||
| 671 | static int panic (lua_State *L) { | 666 | static int panic (lua_State *L) { |
| 672 | (void)L; /* to avoid warnings */ | ||
| 673 | fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", | 667 | fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", |
| 674 | lua_tostring(L, -1)); | 668 | lua_tostring(L, -1)); |
| 675 | exit(EXIT_FAILURE); /* do not return to Lua */ | 669 | exit(EXIT_FAILURE); /* do not return to Lua */ |
