about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-06 19:21:01 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-11-06 19:21:01 -0700
commit5619f0117a15e67dfc0b12f21d58be41450d738f (patch)
treec61f963db2febcead995a52c66aff7c56bdf4be2
parent8d5d27af0c206b827e379c67c7073b71251bb275 (diff)
downloadteliva-5619f0117a15e67dfc0b12f21d58be41450d738f.tar.gz
window:nodelay() for non-blocking input
-rw-r--r--src/lcurseslib.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lcurseslib.c b/src/lcurseslib.c
index 5a5b8b0..000a1ea 100644
--- a/src/lcurseslib.c
+++ b/src/lcurseslib.c
@@ -74,6 +74,12 @@ argtypeerror(lua_State *L, int narg, const char *expected)
 }
 
 
+static void checktype (lua_State *L, int narg, int t, const char *expected) {
+  if (lua_type(L, narg) != t)
+    argtypeerror(L, narg, expected);
+}
+
+
 static lua_Integer checkinteger (lua_State *L, int narg, const char *expected) {
   lua_Integer d = lua_tointeger(L, narg);
   if (d == 0 && !lua_isnumber(L, narg))
@@ -270,6 +276,15 @@ static int Wmvaddstr (lua_State *L) {
 }
 
 
+static int Wnodelay (lua_State *L) {
+  WINDOW *w = checkwin(L, 1);
+  checktype(L, 2, LUA_TBOOLEAN, "boolean or nil");
+  int bf = (int)lua_toboolean(L, 2);
+  lua_pushboolean(L, nodelay(w, bf));
+  return 1;
+}
+
+
 static const luaL_Reg curses_window_methods[] =
 {
   {"__tostring", W__tostring},
@@ -281,6 +296,7 @@ static const luaL_Reg curses_window_methods[] =
   {"getyx", Wgetyx},
   {"mvaddch", Wmvaddch},
   {"mvaddstr", Wmvaddstr},
+  {"nodelay", Wnodelay},
   {NULL, NULL}
 };