about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-05 12:25:31 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-11-05 12:25:31 -0700
commita4ce7ffbd0b74afbd7e06cb553b7cddafee96d01 (patch)
tree51cae755e16b480b6f27bf002fa5c81a76007465
parent595a96367133a8646cd9a992327e54d6b727d696 (diff)
downloadteliva-a4ce7ffbd0b74afbd7e06cb553b7cddafee96d01.tar.gz
window:getmaxyx()
-rw-r--r--src/hanoi.lua3
-rw-r--r--src/lcurseslib.c22
2 files changed, 23 insertions, 2 deletions
diff --git a/src/hanoi.lua b/src/hanoi.lua
index 6a2311d..f3d08fa 100644
--- a/src/hanoi.lua
+++ b/src/hanoi.lua
@@ -36,8 +36,7 @@ end
 
 local function render(screen)
   screen:clear()
-  local lines = curses.lines()
-  local cols = curses.cols()
+  local lines, cols = screen:getmaxyx()
   local line = math.floor(lines/2)
   local col = math.floor(cols/4)
   for i,t in ipairs(tower) do
diff --git a/src/lcurseslib.c b/src/lcurseslib.c
index 3aeba75..baafbf5 100644
--- a/src/lcurseslib.c
+++ b/src/lcurseslib.c
@@ -109,11 +109,33 @@ static int Wclear (lua_State *L) {
 }
 
 
+static int Wgetyx (lua_State *L) {
+  WINDOW *w = checkwin(L, 1);
+  int y, x;
+  getyx(w, y, x);
+  lua_pushinteger(L, y);
+  lua_pushinteger(L, x);
+  return 2;
+}
+
+
+static int Wgetmaxyx (lua_State *L) {
+  WINDOW *w = checkwin(L, 1);
+  int y, x;
+  getmaxyx(w, y, x);
+  lua_pushinteger(L, y);
+  lua_pushinteger(L, x);
+  return 2;
+}
+
+
 static const luaL_Reg curses_window_methods[] =
 {
   {"__tostring", W__tostring},
   {"addstr", Waddstr},
   {"clear", Wclear},
+  {"getmaxyx", Wgetmaxyx},
+  {"getyx", Wgetyx},
   {NULL, NULL}
 };