diff options
| -rw-r--r-- | liolib.c | 14 | ||||
| -rw-r--r-- | lualib.h | 6 |
2 files changed, 11 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.51 2004/05/10 20:26:37 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.52 2004/05/28 18:32:51 roberto Exp roberto $ |
| 3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -30,8 +30,6 @@ | |||
| 30 | */ | 30 | */ |
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | #define FILEHANDLE "FILE*" | ||
| 34 | |||
| 35 | #define IO_INPUT 1 | 33 | #define IO_INPUT 1 |
| 36 | #define IO_OUTPUT 2 | 34 | #define IO_OUTPUT 2 |
| 37 | 35 | ||
| @@ -54,14 +52,14 @@ static int pushresult (lua_State *L, int i, const char *filename) { | |||
| 54 | 52 | ||
| 55 | 53 | ||
| 56 | static FILE **topfile (lua_State *L, int findex) { | 54 | static FILE **topfile (lua_State *L, int findex) { |
| 57 | FILE **f = (FILE **)luaL_checkudata(L, findex, FILEHANDLE); | 55 | FILE **f = (FILE **)luaL_checkudata(L, findex, LUA_FILEHANDLE); |
| 58 | if (f == NULL) luaL_argerror(L, findex, "bad file"); | 56 | if (f == NULL) luaL_argerror(L, findex, "bad file"); |
| 59 | return f; | 57 | return f; |
| 60 | } | 58 | } |
| 61 | 59 | ||
| 62 | 60 | ||
| 63 | static int io_type (lua_State *L) { | 61 | static int io_type (lua_State *L) { |
| 64 | FILE **f = (FILE **)luaL_checkudata(L, 1, FILEHANDLE); | 62 | FILE **f = (FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE); |
| 65 | if (f == NULL) lua_pushnil(L); | 63 | if (f == NULL) lua_pushnil(L); |
| 66 | else if (*f == NULL) | 64 | else if (*f == NULL) |
| 67 | lua_pushliteral(L, "closed file"); | 65 | lua_pushliteral(L, "closed file"); |
| @@ -88,7 +86,7 @@ static FILE *tofile (lua_State *L, int findex) { | |||
| 88 | static FILE **newfile (lua_State *L) { | 86 | static FILE **newfile (lua_State *L) { |
| 89 | FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); | 87 | FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); |
| 90 | *pf = NULL; /* file handle is currently `closed' */ | 88 | *pf = NULL; /* file handle is currently `closed' */ |
| 91 | luaL_getmetatable(L, FILEHANDLE); | 89 | luaL_getmetatable(L, LUA_FILEHANDLE); |
| 92 | lua_setmetatable(L, -2); | 90 | lua_setmetatable(L, -2); |
| 93 | return pf; | 91 | return pf; |
| 94 | } | 92 | } |
| @@ -193,7 +191,7 @@ static int io_readline (lua_State *L); | |||
| 193 | 191 | ||
| 194 | 192 | ||
| 195 | static void aux_lines (lua_State *L, int idx, int close) { | 193 | static void aux_lines (lua_State *L, int idx, int close) { |
| 196 | lua_getfield(L, LUA_REGISTRYINDEX, FILEHANDLE); | 194 | lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); |
| 197 | lua_pushvalue(L, idx); | 195 | lua_pushvalue(L, idx); |
| 198 | lua_pushboolean(L, close); /* close/not close file when finished */ | 196 | lua_pushboolean(L, close); /* close/not close file when finished */ |
| 199 | lua_pushcclosure(L, io_readline, 3); | 197 | lua_pushcclosure(L, io_readline, 3); |
| @@ -460,7 +458,7 @@ static const luaL_reg flib[] = { | |||
| 460 | 458 | ||
| 461 | 459 | ||
| 462 | static void createmeta (lua_State *L) { | 460 | static void createmeta (lua_State *L) { |
| 463 | luaL_newmetatable(L, FILEHANDLE); /* create new metatable for file handles */ | 461 | luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ |
| 464 | /* create (and set) default files */ | 462 | /* create (and set) default files */ |
| 465 | *newfile(L) = stdin; | 463 | *newfile(L) = stdin; |
| 466 | lua_rawseti(L, -2, IO_INPUT); | 464 | lua_rawseti(L, -2, IO_INPUT); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lualib.h,v 1.28 2003/03/18 12:24:26 roberto Exp roberto $ | 2 | ** $Id: lualib.h,v 1.29 2004/03/24 15:46:49 roberto Exp roberto $ |
| 3 | ** Lua standard libraries | 3 | ** Lua standard libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -16,6 +16,10 @@ | |||
| 16 | #endif | 16 | #endif |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | /* Key to file-handle type */ | ||
| 20 | #define LUA_FILEHANDLE "FILE*" | ||
| 21 | |||
| 22 | |||
| 19 | #define LUA_COLIBNAME "coroutine" | 23 | #define LUA_COLIBNAME "coroutine" |
| 20 | LUALIB_API int luaopen_base (lua_State *L); | 24 | LUALIB_API int luaopen_base (lua_State *L); |
| 21 | 25 | ||
