diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-05 13:23:14 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-05 13:23:14 -0700 |
commit | 44258f765700bf07499c9a0e19069ab8b789f98a (patch) | |
tree | 941f75927ed1c01606642eb9c5a69cc23511a5cb /src | |
parent | 14b16003b1e8facb821b54de00ef640a696f5338 (diff) | |
download | teliva-44258f765700bf07499c9a0e19069ab8b789f98a.tar.gz |
window:getch()
But how do we get curses.getch() to work? I don't see it implemented in lcurses.
Diffstat (limited to 'src')
-rw-r--r-- | src/hanoi.lua | 9 | ||||
-rw-r--r-- | src/lcurseslib.c | 13 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/hanoi.lua b/src/hanoi.lua index d8c6cb6..f3d08fa 100644 --- a/src/hanoi.lua +++ b/src/hanoi.lua @@ -65,11 +65,10 @@ end local function main() local screen = curses.stdscr() - render(screen) ---? while true do ---? render(screen) ---? update(screen) ---? end + while true do + render(screen) + update(screen) + end end diff --git a/src/lcurseslib.c b/src/lcurseslib.c index e32ce31..85ef62a 100644 --- a/src/lcurseslib.c +++ b/src/lcurseslib.c @@ -135,6 +135,18 @@ static int Wclear (lua_State *L) { } +static int Wgetch (lua_State *L) { + WINDOW *w = checkwin(L, 1); + int c = wgetch(w); + + if (c == ERR) + return 0; + + lua_pushinteger(L, c); + return 1; +} + + static int Wgetyx (lua_State *L) { WINDOW *w = checkwin(L, 1); int y, x; @@ -183,6 +195,7 @@ static const luaL_Reg curses_window_methods[] = {"attroff", Wattroff}, {"attron", Wattron}, {"clear", Wclear}, + {"getch", Wgetch}, {"getmaxyx", Wgetmaxyx}, {"getyx", Wgetyx}, {"mvaddch", Wmvaddch}, |