diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-07-05 16:41:16 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-07-05 16:41:16 +0000 |
commit | beb9066d9f7c1c04334e3a833999fccd2411de63 (patch) | |
tree | b1314f63681844815a6ee539448c1aa0d6ea7b2a /apps | |
parent | fd0d7c7438c8e97c51172fce1e9d8172a9dd031d (diff) |
Lua: implement gui_syncyesno_run
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21662 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/lua/rockconf.h | 1 | ||||
-rw-r--r-- | apps/plugins/lua/rocklib.c | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/apps/plugins/lua/rockconf.h b/apps/plugins/lua/rockconf.h index b72ebeacd0..67994bb3ca 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 69e26fdee6..8dd738e02a 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}, |