about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-05 13:23:14 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-11-05 13:23:14 -0700
commit44258f765700bf07499c9a0e19069ab8b789f98a (patch)
tree941f75927ed1c01606642eb9c5a69cc23511a5cb
parent14b16003b1e8facb821b54de00ef640a696f5338 (diff)
downloadteliva-44258f765700bf07499c9a0e19069ab8b789f98a.tar.gz
window:getch()
But how do we get curses.getch() to work?
I don't see it implemented in lcurses.
-rw-r--r--src/hanoi.lua9
-rw-r--r--src/lcurseslib.c13
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},
'>1814dcdd ^
b1375328 ^



c182f3ec ^
b1375328 ^


41fe8c22 ^
b1375328 ^





68ed20f1 ^





b1375328 ^


e94b604b ^
e0dfe483 ^
b1375328 ^


e0dfe483 ^

d944e825 ^


9d782fa6 ^
1bc69418 ^




a308f5e4 ^

9d782fa6 ^
7bc160c2 ^
1bc69418 ^




b68d2ce1 ^

1bc69418 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83