mirror of
https://github.com/lua/lua
synced 2025-04-10 23:12:51 +03:00
new function `io.type'
This commit is contained in:
parent
041cb96992
commit
90d7892007
16
liolib.c
16
liolib.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: liolib.c,v 2.25 2002/11/25 15:05:39 roberto Exp roberto $
|
** $Id: liolib.c,v 2.26 2002/12/04 15:17:36 roberto Exp roberto $
|
||||||
** Standard I/O (and system) library
|
** Standard I/O (and system) library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -65,6 +65,19 @@ static FILE **topfile (lua_State *L, int findex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int io_type (lua_State *L) {
|
||||||
|
FILE **f = (FILE **)lua_touserdata(L, 1);
|
||||||
|
if (f == NULL || !lua_getmetatable(L, 1) ||
|
||||||
|
!lua_rawequal(L, -1, lua_upvalueindex(1)))
|
||||||
|
lua_pushnil(L);
|
||||||
|
else if (*f == NULL)
|
||||||
|
lua_pushliteral(L, "closed file");
|
||||||
|
else
|
||||||
|
lua_pushliteral(L, "file");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static FILE *tofile (lua_State *L, int findex) {
|
static FILE *tofile (lua_State *L, int findex) {
|
||||||
FILE **f = topfile(L, findex);
|
FILE **f = topfile(L, findex);
|
||||||
if (*f == NULL)
|
if (*f == NULL)
|
||||||
@ -464,6 +477,7 @@ static const luaL_reg iolib[] = {
|
|||||||
{"popen", io_popen},
|
{"popen", io_popen},
|
||||||
{"read", io_read},
|
{"read", io_read},
|
||||||
{"tmpfile", io_tmpfile},
|
{"tmpfile", io_tmpfile},
|
||||||
|
{"type", io_type},
|
||||||
{"write", io_write},
|
{"write", io_write},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user