aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--com32/lua/src/Makefile4
-rw-r--r--com32/lua/src/cmenu.c90
2 files changed, 94 insertions, 0 deletions
diff --git a/com32/lua/src/Makefile b/com32/lua/src/Makefile
index 20650efd..c8a141f5 100644
--- a/com32/lua/src/Makefile
+++ b/com32/lua/src/Makefile
@@ -32,6 +32,7 @@ MODULES += lfs.c32
MODULES += pci.c32
MODULES += syslinux.c32
MODULES += vesa.c32
+MODULES += cmenu.c32
TESTFILES =
OBJS = lua.o
@@ -56,6 +57,9 @@ liblua.elf : $(LIBLUA_OBJS)
lua.elf : $(OBJS) $(LIBLUA) $(C_LIBS)
$(LD) $(LDFLAGS) -o $@ $^
+cmenu.o : CFLAGS += -I$(com32)/cmenu/libmenu
+cmenu.elf : $(objdir)/com32/cmenu/libmenu/libmenu.c32
+
tidy dist:
rm -f *.o *.lo *.lst *.elf .*.d *.tmp
diff --git a/com32/lua/src/cmenu.c b/com32/lua/src/cmenu.c
new file mode 100644
index 00000000..1b128618
--- /dev/null
+++ b/com32/lua/src/cmenu.c
@@ -0,0 +1,90 @@
+#include "cmenu.h"
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+static int l_init (lua_State *L)
+{
+ init_menusystem (luaL_optstring (L, 1, NULL));
+ return 0;
+}
+
+static int l_set_window_size (lua_State *L)
+{
+ set_window_size (luaL_checkint (L, 1), luaL_checkint (L, 2),
+ luaL_checkint (L, 3), luaL_checkint (L, 4));
+ return 0;
+}
+
+static int l_add_menu (lua_State *L)
+{
+ lua_pushinteger (L, add_menu (luaL_checkstring (L, 1),
+ luaL_optint (L, 2, -1)));
+ return 1;
+}
+
+static int l_add_named_menu (lua_State *L)
+{
+ lua_pushinteger (L, add_named_menu (luaL_checkstring (L, 1),
+ luaL_checkstring (L, 2),
+ luaL_optint (L, 3, -1)));
+ return 1;
+}
+
+static int l_add_item (lua_State *L)
+{
+ add_item (luaL_checkstring (L, 1), luaL_checkstring (L, 2), luaL_checkint (L, 3),
+ luaL_optstring (L, 4, NULL), luaL_optint (L, 5, 0));
+ return 0; /* FIXME return menuitem for advanced functions */
+}
+
+static int l_add_sep (lua_State *L)
+{
+ add_sep ();
+ return 0; /* FIXME return menuitem for advanced functions */
+}
+
+static int l_find_menu_num (lua_State *L)
+{
+ lua_pushinteger (L, find_menu_num (luaL_checkstring (L, 1)));
+ return 1;
+}
+
+static int l_showmenus (lua_State *L)
+{
+ t_menuitem *reply = showmenus (luaL_checkint (L, 1));
+ if (!reply) return 0;
+ lua_pushinteger (L, reply->action);
+ lua_pushstring (L, reply->data);
+ return 2;
+}
+
+static const luaL_Reg menulib[] = {
+ {"init", l_init},
+ {"set_window_size", l_set_window_size},
+ {"add_menu", l_add_menu},
+ {"add_named_menu", l_add_named_menu},
+ {"add_item", l_add_item},
+ {"add_sep", l_add_sep},
+ {"find_menu_num", l_find_menu_num},
+ {"showmenus", l_showmenus},
+ {NULL, NULL}
+};
+
+LUALIB_API int luaopen_cmenu (lua_State *L) {
+ luaL_newlib(L, menulib);
+ lua_newtable (L);
+#define export_opt(x) lua_pushinteger (L, OPT_##x); lua_setfield (L, -2, #x);
+ export_opt (INACTIVE);
+ export_opt (SUBMENU);
+ export_opt (RUN);
+ export_opt (EXITMENU);
+ export_opt (CHECKBOX);
+ export_opt (RADIOMENU);
+ export_opt (SEP);
+ export_opt (INVISIBLE);
+ export_opt (RADIOITEM);
+ lua_setfield (L, -2, "action");
+ return 1;
+}