diff options
author | Thijs <thijs@thijsschreijer.nl> | 2023-11-12 23:53:26 +0100 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2023-11-15 19:17:57 +0100 |
commit | 5f3951a942fdc4bf489d8d590bfc891ac9548a23 (patch) | |
tree | 8d0b7d2e10b45f022d8562cd974a3b7537d1dd7c /src/term.c | |
parent | d45768de3e6f7b28bfecf4d19b192ccac9ce5dc2 (diff) | |
download | luasystem-5f3951a942fdc4bf489d8d590bfc891ac9548a23.tar.gz luasystem-5f3951a942fdc4bf489d8d590bfc891ac9548a23.tar.bz2 luasystem-5f3951a942fdc4bf489d8d590bfc891ac9548a23.zip |
feat(tty): add isatty()
Diffstat (limited to 'src/term.c')
-rw-r--r-- | src/term.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/term.c b/src/term.c new file mode 100644 index 0000000..2adb1e9 --- /dev/null +++ b/src/term.c | |||
@@ -0,0 +1,37 @@ | |||
1 | /// @submodule system | ||
2 | #include <lua.h> | ||
3 | #include <lauxlib.h> | ||
4 | #include <lualib.h> | ||
5 | #include "compat.h" | ||
6 | |||
7 | #ifndef _MSC_VER | ||
8 | # include <unistd.h> | ||
9 | #endif | ||
10 | |||
11 | |||
12 | /*** | ||
13 | Checks if a file-handle is a TTY. | ||
14 | |||
15 | @function isatty | ||
16 | @tparam file file the file-handle to check | ||
17 | @treturn boolean true if the file is a tty | ||
18 | */ | ||
19 | static int lua_isatty(lua_State* L) { | ||
20 | FILE **fh = (FILE **) luaL_checkudata(L, 1, LUA_FILEHANDLE); | ||
21 | lua_pushboolean(L, isatty(fileno(*fh))); | ||
22 | return 1; | ||
23 | } | ||
24 | |||
25 | |||
26 | |||
27 | static luaL_Reg func[] = { | ||
28 | { "isatty", lua_isatty }, | ||
29 | { NULL, NULL } | ||
30 | }; | ||
31 | |||
32 | /*------------------------------------------------------------------------- | ||
33 | * Initializes module | ||
34 | *-------------------------------------------------------------------------*/ | ||
35 | void term_open(lua_State *L) { | ||
36 | luaL_setfuncs(L, func, 0); | ||
37 | } | ||