Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/trepl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/utils.c b/utils.c
new file mode 100644
index 0000000..62a3e4e
--- /dev/null
+++ b/utils.c
@@ -0,0 +1,41 @@
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#if LUA_VERSION_NUM == 501
+# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
+# define luaL_setfuncs(L, libs, _) luaL_register(L, NULL, libs)
+#else
+# define lua_strlen lua_rawlen
+#endif
+
+#if defined(_WIN32) || defined(LUA_WIN)
+
+int treplutils_isatty(lua_State *L)
+{
+ lua_pushboolean(L, 0);
+ return 1;
+}
+
+#else
+
+#include <unistd.h>
+
+int treplutils_isatty(lua_State *L)
+{
+ lua_pushboolean(L, isatty(1));
+ return 1;
+}
+
+#endif
+
+static const struct luaL_Reg utils[] = {
+ {"isatty", treplutils_isatty},
+ {NULL, NULL}
+};
+
+int luaopen_treplutils(lua_State *L) {
+ lua_newtable(L);
+ luaL_setfuncs(L, utils, 0);
+ return 1;
+}