diff options
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); +} |