about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-05 12:52:37 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-11-05 12:57:13 -0700
commit13784eb757f69eba9071ace9fc245746323cc5a1 (patch)
tree5a97e6fd0389b06b42e82c3dd765d8cd0523dc43
parent6f96d30641dde351f12279920ef6dc6b9187c25f (diff)
downloadteliva-13784eb757f69eba9071ace9fc245746323cc5a1.tar.gz
mvaddch/mvaddstr
I think we now have all the output functions/methods we need. Just some
constants remaining.
-rw-r--r--src/lcurseslib.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lcurseslib.c b/src/lcurseslib.c
index 1c38258..4704003 100644
--- a/src/lcurseslib.c
+++ b/src/lcurseslib.c
@@ -75,6 +75,16 @@ static lua_Integer checkinteger (lua_State *L, int narg, const char *expected) {
 }
 
 
+static chtype checkch (lua_State *L, int narg) {
+  if (lua_isnumber(L, narg))
+    return cast(chtype, checkinteger(L, narg, "int"));
+  if (lua_isstring(L, narg))
+    return *lua_tostring(L, narg);
+
+  return argtypeerror(L, narg, "int or char");
+}
+
+
 static int optint (lua_State *L, int narg, lua_Integer def) {
   if (lua_isnoneornil(L, narg))
     return cast(int, def);
@@ -145,6 +155,27 @@ static int Wgetmaxyx (lua_State *L) {
 }
 
 
+static int Wmvaddch (lua_State *L) {
+  WINDOW *w = checkwin(L, 1);
+  int y = checkinteger(L, 2, "int");
+  int x = checkinteger(L, 3, "int");
+  chtype ch = checkch(L, 4);
+  mvwaddch(w, y, x, ch);
+  return 1;
+}
+
+
+static int Wmvaddstr (lua_State *L) {
+  WINDOW *w = checkwin(L, 1);
+  int y = checkinteger(L, 2, "int");
+  int x = checkinteger(L, 3, "int");
+  const char *str = luaL_checkstring(L, 4);
+  int n = optint(L, 5, -1);
+  mvwaddnstr(w, y, x, str, n);
+  return 1;
+}
+
+
 static const luaL_Reg curses_window_methods[] =
 {
   {"__tostring", W__tostring},
@@ -154,6 +185,8 @@ static const luaL_Reg curses_window_methods[] =
   {"clear", Wclear},
   {"getmaxyx", Wgetmaxyx},
   {"getyx", Wgetyx},
+  {"mvaddch", Wmvaddch},
+  {"mvaddstr", Wmvaddstr},
   {NULL, NULL}
 };