summaryrefslogtreecommitdiff
path: root/apps/plugins/lua
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2009-10-23 10:38:20 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2009-10-23 10:38:20 +0000
commit9dd25adae488ef5461f2cf6fabb25ac974703be4 (patch)
tree8370aed42deb4887c10b89e4fff1a27f1137b578 /apps/plugins/lua
parentff8e9d95ee1f33b9e5fba10626649984853a8a7c (diff)
downloadrockbox-9dd25adae488ef5461f2cf6fabb25ac974703be4.zip
rockbox-9dd25adae488ef5461f2cf6fabb25ac974703be4.tar.gz
rockbox-9dd25adae488ef5461f2cf6fabb25ac974703be4.tar.bz2
rockbox-9dd25adae488ef5461f2cf6fabb25ac974703be4.tar.xz
Lua: add do_menu() wrapper. Also fix potential NULL pointer dereference
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23320 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lua')
-rw-r--r--apps/plugins/lua/rocklib.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index c6b399c..cb90edd 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -503,6 +503,8 @@ static void fill_text_message(lua_State *L, struct text_message * message,
luaL_checktype(L, pos, LUA_TTABLE);
int n = luaL_getn(L, pos);
const char **lines = (const char**) dlmalloc(n * sizeof(const char*));
+ if(lines == NULL)
+ luaL_error(L, "Can't allocate %d bytes!", n * sizeof(const char*));
for(i=1; i<=n; i++)
{
lua_rawgeti(L, pos, i);
@@ -536,6 +538,41 @@ RB_WRAP(gui_syncyesno_run)
return 1;
}
+RB_WRAP(do_menu)
+{
+ struct menu_callback_with_desc menu_desc = {NULL, NULL, Icon_NOICON};
+ struct menu_item_ex menu = {MT_RETURN_ID | MENU_HAS_DESC, {.strings = NULL},
+ {.callback_and_desc = &menu_desc}};
+ int i, n, start_selected;
+ const char **items, *title;
+
+ title = luaL_checkstring(L, 1);
+ luaL_checktype(L, 2, LUA_TTABLE);
+ start_selected = luaL_optint(L, 3, 0);
+
+ n = luaL_getn(L, 2);
+ items = (const char**) dlmalloc(n * sizeof(const char*));
+ if(items == NULL)
+ luaL_error(L, "Can't allocate %d bytes!", n * sizeof(const char*));
+ for(i=1; i<=n; i++)
+ {
+ lua_rawgeti(L, 2, i); /* Push item on the stack */
+ items[i-1] = luaL_checkstring(L, -1);
+ lua_pop(L, 1); /* Pop it */
+ }
+
+ menu.strings = items;
+ menu.flags |= MENU_ITEM_COUNT(n);
+ menu_desc.desc = (unsigned char*) title;
+
+ int result = rb->do_menu(&menu, &start_selected, NULL, false);
+
+ dlfree(items);
+
+ lua_pushinteger(L, result);
+ return 1;
+}
+
#define R(NAME) {#NAME, rock_##NAME}
static const luaL_Reg rocklib[] =
{
@@ -575,6 +612,7 @@ static const luaL_Reg rocklib[] =
R(clear_viewport),
R(current_path),
R(gui_syncyesno_run),
+ R(do_menu),
{"new_image", rli_new},