about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/hanoi.lua8
-rw-r--r--src/lcurseslib.c32
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}