diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-05-28 15:35:05 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-05-28 15:35:05 -0300 |
commit | 0733c83b8ce08234aa4b9b4889bae029dcfb8414 (patch) | |
tree | 5c909ec06993c42a64d31a35eeed3aea5b5a751d /liolib.c | |
parent | e9844a4f1d8a4cb9642c00db552a40f65f3748b8 (diff) | |
download | lua-0733c83b8ce08234aa4b9b4889bae029dcfb8414.tar.gz lua-0733c83b8ce08234aa4b9b4889bae029dcfb8414.tar.bz2 lua-0733c83b8ce08234aa4b9b4889bae029dcfb8414.zip |
other modules may need FILEHANDLE definition
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 14 |
1 files changed, 6 insertions, 8 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); |