From 113a819dbb2ddf94e2053b325313f3db690aa9e2 Mon Sep 17 00:00:00 2001 From: mcuelenaere Date: Sun, 5 Jul 2009 16:41:16 +0000 Subject: [PATCH] Lua: implement gui_syncyesno_run git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21662 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/lua/rockconf.h | 1 + apps/plugins/lua/rocklib.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/apps/plugins/lua/rockconf.h b/apps/plugins/lua/rockconf.h index b72ebeacd..67994bb3c 100644 --- a/apps/plugins/lua/rockconf.h +++ b/apps/plugins/lua/rockconf.h @@ -44,6 +44,7 @@ #define luai_jmpbuf jmp_buf extern char curpath[MAX_PATH]; +void* dlmalloc(size_t bytes); void *dlrealloc(void *ptr, size_t size); void dlfree(void *ptr); struct tm *gmtime(const time_t *timep); diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 69e26fdee..8dd738e02 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c @@ -480,6 +480,46 @@ RB_WRAP(current_path) return 0; } +static void fill_text_message(lua_State *L, struct text_message * message, + int pos) +{ + int i; + luaL_checktype(L, pos, LUA_TTABLE); + int n = luaL_getn(L, pos); + const char **lines = (const char**) dlmalloc(n * sizeof(const char*)); + for(i=1; i<=n; i++) + { + lua_rawgeti(L, pos, i); + lines[i-1] = luaL_checkstring(L, -1); + lua_pop(L, 1); + } + message->message_lines = lines; + message->nb_lines = n; +} + +RB_WRAP(gui_syncyesno_run) +{ + struct text_message main_message, yes_message, no_message; + struct text_message *yes = NULL, *no = NULL; + + fill_text_message(L, &main_message, 1); + if(!lua_isnoneornil(L, 2)) + fill_text_message(L, (yes = &yes_message), 2); + if(!lua_isnoneornil(L, 3)) + fill_text_message(L, (no = &no_message), 3); + + enum yesno_res result = rb->gui_syncyesno_run(&main_message, yes, no); + + dlfree(main_message.message_lines); + if(yes) + dlfree(yes_message.message_lines); + if(no) + dlfree(no_message.message_lines); + + lua_pushinteger(L, result); + return 1; +} + #define R(NAME) {#NAME, rock_##NAME} static const luaL_Reg rocklib[] = { @@ -518,6 +558,7 @@ static const luaL_Reg rocklib[] = R(set_viewport), R(clear_viewport), R(current_path), + R(gui_syncyesno_run), {"new_image", rli_new}, -- 2.11.4.GIT