From a4ce7ffbd0b74afbd7e06cb553b7cddafee96d01 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 5 Nov 2021 12:25:31 -0700 Subject: window:getmaxyx() --- src/hanoi.lua | 3 +-- src/lcurseslib.c | 22 ++++++++++++++++++++++ 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} }; -- cgit 1.4.1-2-gfad0