summaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-12-04 13:27:17 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-12-04 13:27:17 -0200
commit90d7892007e399765cf8d14f65f7e3bc4a96e087 (patch)
treefbf3718bf5a562e9275e080c10ad565f153a127a /liolib.c
parent041cb9699284399a5068c91ced2df3f298276c0b (diff)
downloadlua-90d7892007e399765cf8d14f65f7e3bc4a96e087.tar.gz
lua-90d7892007e399765cf8d14f65f7e3bc4a96e087.tar.bz2
lua-90d7892007e399765cf8d14f65f7e3bc4a96e087.zip
new function `io.type'
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/liolib.c b/liolib.c
index 4bf2d5bc..2d881875 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.25 2002/11/25 15:05:39 roberto Exp roberto $ 2** $Id: liolib.c,v 2.26 2002/12/04 15:17:36 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*/
@@ -65,6 +65,19 @@ static FILE **topfile (lua_State *L, int findex) {
65} 65}
66 66
67 67
68static int io_type (lua_State *L) {
69 FILE **f = (FILE **)lua_touserdata(L, 1);
70 if (f == NULL || !lua_getmetatable(L, 1) ||
71 !lua_rawequal(L, -1, lua_upvalueindex(1)))
72 lua_pushnil(L);
73 else if (*f == NULL)
74 lua_pushliteral(L, "closed file");
75 else
76 lua_pushliteral(L, "file");
77 return 1;
78}
79
80
68static FILE *tofile (lua_State *L, int findex) { 81static FILE *tofile (lua_State *L, int findex) {
69 FILE **f = topfile(L, findex); 82 FILE **f = topfile(L, findex);
70 if (*f == NULL) 83 if (*f == NULL)
@@ -464,6 +477,7 @@ static const luaL_reg iolib[] = {
464 {"popen", io_popen}, 477 {"popen", io_popen},
465 {"read", io_read}, 478 {"read", io_read},
466 {"tmpfile", io_tmpfile}, 479 {"tmpfile", io_tmpfile},
480 {"type", io_type},
467 {"write", io_write}, 481 {"write", io_write},
468 {NULL, NULL} 482 {NULL, NULL}
469}; 483};