summaryrefslogtreecommitdiffstats
path: root/apps/plugins/lua/rocklib.c
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-10-23 01:57:41 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2018-10-25 12:06:10 +0200
commitb5786ded6482b5b5955b96bf61b410f012a8509a (patch)
treecc4b410cdb9d91c0f93bdf4c6c375f4023351612 /apps/plugins/lua/rocklib.c
parente4c5f5d412d94b10545980eea0b47d98e79712da (diff)
downloadrockbox-b5786ded6482b5b5955b96bf61b410f012a8509a.tar.gz
rockbox-b5786ded6482b5b5955b96bf61b410f012a8509a.zip
Lua cleanup kbd_input, gui_syncyesno_run, do_menu
Removes unneeded functions from kbd_input Consolidates message filling function for gui_syncyesno_run & do_menu Change-Id: If3c3cea3cbf37a8dc52983c0db174de6d54b35f8
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r--apps/plugins/lua/rocklib.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 5166291cf5..1b928c229c 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -131,17 +131,17 @@ RB_WRAP(kbd_input)
char *buffer = luaL_prepbuffer(&b);
if(input != NULL)
- rb->strlcpy(buffer, input, LUAL_BUFFERSIZE);
+ luaL_addstring(&b, input);
else
buffer[0] = '\0';
if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE))
{
- luaL_addsize(&b, strlen(buffer));
+ luaL_addstring(&b, buffer);
luaL_pushresult(&b);
}
else
- lua_pushnil(L);
+ return 0;
return 1;
}
@@ -196,22 +196,32 @@ RB_WRAP(current_path)
return get_current_path(L, 1);
}
-static void fill_text_message(lua_State *L, struct text_message * message,
- int pos)
+static const char ** get_table_items(lua_State *L, int pos, int *count)
{
int i;
luaL_checktype(L, pos, LUA_TTABLE);
- int n = luaL_getn(L, pos);
+ *count = lua_objlen(L, pos);
+ int n = *count;
- const char **lines = (const char**) lua_newuserdata(L, n * sizeof(const char*));
+ /* newuserdata will be pushed onto stack after args*/
+ const char **items = (const char**) lua_newuserdata(L, n * sizeof(const char*));
- for(i=1; i<=n; i++)
+ for(i=1; i<= n; i++)
{
- lua_rawgeti(L, pos, i);
- lines[i-1] = luaL_checkstring(L, -1);
- lua_pop(L, 1);
+ lua_rawgeti(L, pos, i); /* Push item on the stack */
+ items[i-1] = lua_tostring(L, -1);
+ lua_pop(L, 1); /* Pop it */
}
- message->message_lines = lines;
+
+ return items;
+}
+
+static inline void fill_text_message(lua_State *L, struct text_message * message,
+ int pos)
+{
+ int n;
+ /* newuserdata will be pushed onto stack after args*/
+ message->message_lines = get_table_items(L, pos, &n);
message->nb_lines = n;
}
@@ -238,24 +248,15 @@ 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;
+ int n, start_selected;
const char **items, *title;
title = luaL_checkstring(L, 1);
- luaL_checktype(L, 2, LUA_TTABLE);
- start_selected = lua_tointeger(L, 3);
- n = luaL_getn(L, 2);
+ start_selected = lua_tointeger(L, 3);
/* newuserdata will be pushed onto stack after args*/
- items = (const char**) lua_newuserdata(L, 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 */
- }
+ items = get_table_items(L, 2, &n);
menu.strings = items;
menu.flags |= MENU_ITEM_COUNT(n);