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

utils.c - github.com/torch/trepl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b44605146eed4bdc96081b9dace2d76b3a2d7a67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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, _isatty(1));
  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;
}