diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-05 13:34:38 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-05 13:34:38 -0700 |
commit | d04ecfeaf34114666ce80dfd1be03c439d8151d7 (patch) | |
tree | 92f5158f7f5926f76d170a8e9a1f78aaf8f28a12 /src | |
parent | 936f8f916b350e8374e98449413cfe69d1a40842 (diff) | |
download | teliva-d04ecfeaf34114666ce80dfd1be03c439d8151d7.tar.gz |
hanoi.lua _almost_ working
Diffstat (limited to 'src')
-rw-r--r-- | src/hanoi.lua | 8 | ||||
-rw-r--r-- | src/lcurseslib.c | 32 |
2 files changed, 30 insertions, 10 deletions
diff --git a/src/hanoi.lua b/src/hanoi.lua index f3d08fa..b0a75cd 100644 --- a/src/hanoi.lua +++ b/src/hanoi.lua @@ -52,11 +52,11 @@ end local function update(screen) - screen:mvaddstr(curses.lines()-2, 5, "tower to remove top disk from? ") - local from = string.byte(curses.getch()) - 96 + screen:mvaddstr(screen:lines()-2, 5, "tower to remove top disk from? ") + local from = string.byte(screen:getch()) - 96 curses.refresh() - screen:mvaddstr(curses.lines()-1, 5, "tower to stack it on? ") - local to = string.byte(curses.getch()) - 96 + screen:mvaddstr(screen:lines()-1, 5, "tower to stack it on? ") + local to = string.byte(screen:getch()) - 96 curses.refresh() make_move(from, to) end diff --git a/src/lcurseslib.c b/src/lcurseslib.c index 85ef62a..e3e580b 100644 --- a/src/lcurseslib.c +++ b/src/lcurseslib.c @@ -8,21 +8,21 @@ #include "lualib.h" -static int Pstdscr (lua_State *L) { - lua_pushstring(L, "curses:stdscr"); - lua_rawget(L, LUA_REGISTRYINDEX); +static int Prefresh (lua_State *L) { + refresh(); return 1; } -static int Pcols (lua_State *L) { - lua_pushinteger(L, COLS); +static int Pstdscr (lua_State *L) { + lua_pushstring(L, "curses:stdscr"); + lua_rawget(L, LUA_REGISTRYINDEX); return 1; } static const struct luaL_Reg curseslib [] = { - {"cols", Pcols}, + {"refresh", Prefresh}, {"stdscr", Pstdscr}, {NULL, NULL} }; @@ -167,6 +167,24 @@ static int Wgetmaxyx (lua_State *L) { } +static int Wcols (lua_State *L) { + WINDOW *w = checkwin(L, 1); + int y, x; + getmaxyx(w, y, x); + lua_pushinteger(L, x); + return 1; +} + + +static int Wlines (lua_State *L) { + WINDOW *w = checkwin(L, 1); + int y, x; + getmaxyx(w, y, x); + lua_pushinteger(L, y); + return 1; +} + + static int Wmvaddch (lua_State *L) { WINDOW *w = checkwin(L, 1); int y = checkinteger(L, 2, "int"); @@ -195,9 +213,11 @@ static const luaL_Reg curses_window_methods[] = {"attroff", Wattroff}, {"attron", Wattron}, {"clear", Wclear}, + {"cols", Wcols}, {"getch", Wgetch}, {"getmaxyx", Wgetmaxyx}, {"getyx", Wgetyx}, + {"lines", Wlines}, {"mvaddch", Wmvaddch}, {"mvaddstr", Wmvaddstr}, {NULL, NULL} |