about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--hanoi.lua1
-rw-r--r--hanoi.teliva1
-rw-r--r--src/lcurseslib.c16
-rw-r--r--src/lua.c5
4 files changed, 19 insertions, 4 deletions
diff --git a/hanoi.lua b/hanoi.lua
index f216570..0c1d60f 100644
--- a/hanoi.lua
+++ b/hanoi.lua
@@ -1,5 +1,6 @@
 local curses = require "curses"
 
+menu = {a="abc"}
 tower = {{6, 5, 4, 3, 2}, {}, {}}
 
 local function len(array)
diff --git a/hanoi.teliva b/hanoi.teliva
index 04b4491..d0ae354 100644
--- a/hanoi.teliva
+++ b/hanoi.teliva
@@ -1,5 +1,6 @@
 local curses = require "curses"
 
+menu = {a="abc"}
 tower = {{6, 5, 4, 3, 2}, {}, {}}
 
 local function len(array)
diff --git a/src/lcurseslib.c b/src/lcurseslib.c
index ff9e235..9d13f0a 100644
--- a/src/lcurseslib.c
+++ b/src/lcurseslib.c
@@ -36,19 +36,31 @@ void draw_menu_item(const char* key, const char* name) {
   attroff(A_REVERSE);
 }
 
-void draw_menu (void) {
+void draw_menu (lua_State *L) {
   attron(A_BOLD|A_REVERSE);
   for (int x = 0; x < COLS; ++x)
     mvaddch(LINES-1, x, ' ');
   menu_column = 2;
   draw_menu_item("^x", "exit");
   draw_menu_item("^e", "edit");
+
+  /* render any app-specific items */
+  lua_getglobal(L, "menu");
+  int table = lua_gettop(L);
+  if (!lua_istable(L, -1)) {
+    lua_pop(L, 1);
+    return;
+  }
+  for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1))
+    draw_menu_item(lua_tostring(L, -2), lua_tostring(L, -1));
+
+  attroff(A_BOLD);
 }
 
 
 static int Prefresh (lua_State *L) {
   refresh();
-  draw_menu();
+  draw_menu(L);
   return 1;
 }
 
diff --git a/src/lua.c b/src/lua.c
index 7142641..f2676c0 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -368,7 +368,7 @@ static int pmain (lua_State *L) {
 }
 
 
-void draw_menu(void);
+void draw_menu(lua_State *);
 char **Argv = NULL;
 
 
@@ -382,7 +382,7 @@ int main (int argc, char **argv) {
   }
   initscr();
   start_color();
-  draw_menu();
+  draw_menu(L);
   echo();
   s.argc = argc;
   s.argv = argv;
@@ -390,6 +390,7 @@ int main (int argc, char **argv) {
   status = lua_cpcall(L, &pmain, &s);
   report(L, status);
   lua_close(L);
+//?   getch();  /* uncomment this to see some common errors if teliva exits cryptically with a non-zero error code. */
   endwin();
   return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
 }