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 | |
parent | d45768de3e6f7b28bfecf4d19b192ccac9ce5dc2 (diff) | |
download | luasystem-5f3951a942fdc4bf489d8d590bfc891ac9548a23.tar.gz luasystem-5f3951a942fdc4bf489d8d590bfc891ac9548a23.tar.bz2 luasystem-5f3951a942fdc4bf489d8d590bfc891ac9548a23.zip |
feat(tty): add isatty()
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/core.c | 2 | ||||
-rw-r--r-- | src/term.c | 37 |
3 files changed, 40 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile index 119f95e..b4ed16f 100644 --- a/src/Makefile +++ b/src/Makefile | |||
@@ -217,7 +217,7 @@ LUALIB= $(LUALIB_$(PLAT)) | |||
217 | #------ | 217 | #------ |
218 | # Objects | 218 | # Objects |
219 | # | 219 | # |
220 | OBJS=core.$(O) compat.$(O) time.$(O) environment.$(O) random.$(O) | 220 | OBJS=core.$(O) compat.$(O) time.$(O) environment.$(O) random.$(O) term.$(O) |
221 | 221 | ||
222 | #------ | 222 | #------ |
223 | # Targets | 223 | # Targets |
@@ -15,6 +15,7 @@ | |||
15 | void time_open(lua_State *L); | 15 | void time_open(lua_State *L); |
16 | void environment_open(lua_State *L); | 16 | void environment_open(lua_State *L); |
17 | void random_open(lua_State *L); | 17 | void random_open(lua_State *L); |
18 | void term_open(lua_State *L); | ||
18 | 19 | ||
19 | /*------------------------------------------------------------------------- | 20 | /*------------------------------------------------------------------------- |
20 | * Initializes all library modules. | 21 | * Initializes all library modules. |
@@ -33,6 +34,7 @@ LUAEXPORT int luaopen_system_core(lua_State *L) { | |||
33 | lua_rawset(L, -3); | 34 | lua_rawset(L, -3); |
34 | time_open(L); | 35 | time_open(L); |
35 | random_open(L); | 36 | random_open(L); |
37 | term_open(L); | ||
36 | environment_open(L); | 38 | environment_open(L); |
37 | return 1; | 39 | return 1; |
38 | } | 40 | } |
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 | } | ||