diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-05 17:54:45 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-05 17:54:45 -0700 |
commit | 78898d271620ee15ac576f157ca2e942420421fb (patch) | |
tree | 1f0ee675fd217253cc602df7054e0ad3d27fa094 /src | |
parent | 18f06a5169951b4f7d5dc57720c6204672ae8f09 (diff) | |
download | teliva-78898d271620ee15ac576f157ca2e942420421fb.tar.gz |
move getch out of window scope
The window only matters for output, which seems like a stupid interface.
Diffstat (limited to 'src')
-rw-r--r-- | src/hanoi.lua | 4 | ||||
-rw-r--r-- | src/lcurseslib.c | 23 |
2 files changed, 12 insertions, 15 deletions
diff --git a/src/hanoi.lua b/src/hanoi.lua index 0efacd9..9f0b1cf 100644 --- a/src/hanoi.lua +++ b/src/hanoi.lua @@ -63,10 +63,10 @@ end local function update(window) window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ") - local from = window:getch() - 96 + local from = curses.getch() - 96 curses.refresh() window:mvaddstr(lines(window)-1, 5, "tower to stack it on? ") - local to = window:getch() - 96 + local to = curses.getch() - 96 curses.refresh() make_move(from, to) end diff --git a/src/lcurseslib.c b/src/lcurseslib.c index b91818e..e58a5cc 100644 --- a/src/lcurseslib.c +++ b/src/lcurseslib.c @@ -21,7 +21,17 @@ static int Pstdscr (lua_State *L) { } +static int Pgetch (lua_State *L) { + int c = wgetch(stdscr); + if (c == ERR) + return 0; + lua_pushinteger(L, c); + return 1; +} + + static const struct luaL_Reg curseslib [] = { + {"getch", Pgetch}, {"refresh", Prefresh}, {"stdscr", Pstdscr}, {NULL, NULL} @@ -135,18 +145,6 @@ 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; @@ -195,7 +193,6 @@ static const luaL_Reg curses_window_methods[] = {"attroff", Wattroff}, {"attron", Wattron}, {"clear", Wclear}, - {"getch", Wgetch}, {"getmaxyx", Wgetmaxyx}, {"getyx", Wgetyx}, {"mvaddch", Wmvaddch}, |