about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-12-22 00:24:59 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-12-22 00:27:50 -0800
commit343316dcfa7cb1872d3082d88d3811896f6ee2c1 (patch)
treee07bc4816b96d82c9d9f9c9c55a42ee7fd2636dc /src
parentc537e7bc2d55fbc46a77f3e8e4f207acd522ea82 (diff)
downloadteliva-343316dcfa7cb1872d3082d88d3811896f6ee2c1.tar.gz
more precise control over menu order
I can't believe I didn't notice this until now.
Diffstat (limited to 'src')
-rw-r--r--src/menu.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/menu.c b/src/menu.c
index b02c522..72f95ba 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -2,6 +2,7 @@
 #include <string.h>
 
 #include "lua.h"
+#include "lauxlib.h"
 #include "teliva.h"
 
 
@@ -32,9 +33,16 @@ void draw_menu (lua_State *L) {
   /* render any app-specific items */
   lua_getglobal(L, "menu");
   int table = lua_gettop(L);
-  if (lua_istable(L, -1))
-    for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1))
+  if (lua_istable(L, -1)) {
+    for (int i = 1; i <= luaL_getn(L, table); ++i) {
+      lua_rawgeti(L, table, i);
+      int menu_item = lua_gettop(L);
+      lua_rawgeti(L, menu_item, 1);  /* key */
+      lua_rawgeti(L, menu_item, 2);  /* value */
       draw_menu_item(lua_tostring(L, -2), lua_tostring(L, -1));
+      lua_pop(L, 3);
+    }
+  }
 
   lua_pop(L, 1);
   attrset(A_NORMAL);