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.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)) #------ # Objects # -OBJS=core.$(O) compat.$(O) time.$(O) environment.$(O) random.$(O) +OBJS=core.$(O) compat.$(O) time.$(O) environment.$(O) random.$(O) term.$(O) #------ # Targets @@ -15,6 +15,7 @@ void time_open(lua_State *L); void environment_open(lua_State *L); void random_open(lua_State *L); +void term_open(lua_State *L); /*------------------------------------------------------------------------- * Initializes all library modules. @@ -33,6 +34,7 @@ LUAEXPORT int luaopen_system_core(lua_State *L) { lua_rawset(L, -3); time_open(L); random_open(L); + term_open(L); environment_open(L); return 1; } 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 @@ +/// @submodule system +#include <lua.h> +#include <lauxlib.h> +#include <lualib.h> +#include "compat.h" + +#ifndef _MSC_VER +# include <unistd.h> +#endif + + +/*** +Checks if a file-handle is a TTY. + +@function isatty +@tparam file file the file-handle to check +@treturn boolean true if the file is a tty +*/ +static int lua_isatty(lua_State* L) { + FILE **fh = (FILE **) luaL_checkudata(L, 1, LUA_FILEHANDLE); + lua_pushboolean(L, isatty(fileno(*fh))); + return 1; +} + + + +static luaL_Reg func[] = { + { "isatty", lua_isatty }, + { NULL, NULL } +}; + +/*------------------------------------------------------------------------- + * Initializes module + *-------------------------------------------------------------------------*/ +void term_open(lua_State *L) { + luaL_setfuncs(L, func, 0); +} |