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
This commit is contained in:
William Wilgus 2018-10-23 01:57:41 -04:00
parent e4c5f5d412
commit b5786ded64

View file

@ -131,17 +131,17 @@ RB_WRAP(kbd_input)
char *buffer = luaL_prepbuffer(&b); char *buffer = luaL_prepbuffer(&b);
if(input != NULL) if(input != NULL)
rb->strlcpy(buffer, input, LUAL_BUFFERSIZE); luaL_addstring(&b, input);
else else
buffer[0] = '\0'; buffer[0] = '\0';
if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE)) if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE))
{ {
luaL_addsize(&b, strlen(buffer)); luaL_addstring(&b, buffer);
luaL_pushresult(&b); luaL_pushresult(&b);
} }
else else
lua_pushnil(L); return 0;
return 1; return 1;
} }
@ -196,22 +196,32 @@ RB_WRAP(current_path)
return get_current_path(L, 1); return get_current_path(L, 1);
} }
static void fill_text_message(lua_State *L, struct text_message * message, static const char ** get_table_items(lua_State *L, int pos, int *count)
int pos)
{ {
int i; int i;
luaL_checktype(L, pos, LUA_TTABLE); 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); lua_rawgeti(L, pos, i); /* Push item on the stack */
lines[i-1] = luaL_checkstring(L, -1); items[i-1] = lua_tostring(L, -1);
lua_pop(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; 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_callback_with_desc menu_desc = {NULL, NULL, Icon_NOICON};
struct menu_item_ex menu = {MT_RETURN_ID | MENU_HAS_DESC, {.strings = NULL}, struct menu_item_ex menu = {MT_RETURN_ID | MENU_HAS_DESC, {.strings = NULL},
{.callback_and_desc = &menu_desc}}; {.callback_and_desc = &menu_desc}};
int i, n, start_selected; int n, start_selected;
const char **items, *title; const char **items, *title;
title = luaL_checkstring(L, 1); title = luaL_checkstring(L, 1);
luaL_checktype(L, 2, LUA_TTABLE);
start_selected = lua_tointeger(L, 3); start_selected = lua_tointeger(L, 3);
n = luaL_getn(L, 2);
/* newuserdata will be pushed onto stack after args*/ /* newuserdata will be pushed onto stack after args*/
items = (const char**) lua_newuserdata(L, n * sizeof(const char*)); items = get_table_items(L, 2, &n);
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.strings = items;
menu.flags |= MENU_ITEM_COUNT(n); menu.flags |= MENU_ITEM_COUNT(n);