diff options
author | Ferenc Wágner <wferi@niif.hu> | 2013-10-24 14:27:56 +0200 |
---|---|---|
committer | Ferenc Wágner <wferi@niif.hu> | 2014-03-02 09:07:58 +0100 |
commit | 7e6aa0662469fbc910c10afd4b3b0567e4e8eaad (patch) | |
tree | 1ff76e94fc78f2187f22c9375dbdc8d0c90da57b | |
parent | 7c01256715ea611da8ad47c135ae41f5dd54f9e3 (diff) | |
download | syslinux-7e6aa0662469fbc910c10afd4b3b0567e4e8eaad.tar.gz syslinux-7e6aa0662469fbc910c10afd4b3b0567e4e8eaad.tar.xz syslinux-7e6aa0662469fbc910c10afd4b3b0567e4e8eaad.zip |
lua: start of a binding module for libmenu.c32
-rw-r--r-- | com32/lua/src/Makefile | 4 | ||||
-rw-r--r-- | com32/lua/src/cmenu.c | 90 |
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; +} |