diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-05 16:41:31 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-05 16:41:31 -0700 |
commit | c0307fae88cbae73b1dd9a60de973de257d5d1ad (patch) | |
tree | 50b19787402d24828dc9ec636a13137c0ef3baf2 /hanoi.lua | |
parent | 216e56effc28677b0a237b5b0ae834b15aca6f1e (diff) | |
download | teliva-c0307fae88cbae73b1dd9a60de973de257d5d1ad.tar.gz |
resist the temptation to add to the Lua API
Instead we'll include code in the Lua app itself, to minimize the differences between what runs on regular Lua and what runs on Teliva.
Diffstat (limited to 'hanoi.lua')
-rw-r--r-- | hanoi.lua | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/hanoi.lua b/hanoi.lua index 42f6c5e..c9c0158 100644 --- a/hanoi.lua +++ b/hanoi.lua @@ -17,6 +17,16 @@ local function pop(array) return table.remove(array) end +local function lines(window) + local lines, cols = window:getmaxyx() + return lines +end + +local function cols(window) + local lines, cols = window:getmaxyx() + return cols +end + local function render_tower(screen, line, col, tower_index, tower) screen:attron(curses.A_BOLD) @@ -36,8 +46,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 @@ -53,10 +62,10 @@ end local function update(screen) - screen:mvaddstr(curses.lines()-2, 5, "tower to remove top disk from? ") + screen:mvaddstr(lines(screen)-2, 5, "tower to remove top disk from? ") local from = string.byte(curses.getch()) - 96 curses.refresh() - screen:mvaddstr(curses.lines()-1, 5, "tower to stack it on? ") + screen:mvaddstr(lines(screen)-1, 5, "tower to stack it on? ") local to = string.byte(curses.getch()) - 96 curses.refresh() make_move(from, to) |