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 | |
parent | fd0d7c7438c8e97c51172fce1e9d8172a9dd031d (diff) | |
download | rockbox-beb9066d9f7c1c04334e3a833999fccd2411de63.tar.gz rockbox-beb9066d9f7c1c04334e3a833999fccd2411de63.zip |
Lua: implement gui_syncyesno_run
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21662 a1c6a512-1295-4272-9138-f99709370657
-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 @@ | |||
44 | #define luai_jmpbuf jmp_buf | 44 | #define luai_jmpbuf jmp_buf |
45 | 45 | ||
46 | extern char curpath[MAX_PATH]; | 46 | extern char curpath[MAX_PATH]; |
47 | void* dlmalloc(size_t bytes); | ||
47 | void *dlrealloc(void *ptr, size_t size); | 48 | void *dlrealloc(void *ptr, size_t size); |
48 | void dlfree(void *ptr); | 49 | void dlfree(void *ptr); |
49 | struct tm *gmtime(const time_t *timep); | 50 | 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) | |||
480 | return 0; | 480 | return 0; |
481 | } | 481 | } |
482 | 482 | ||
483 | static void fill_text_message(lua_State *L, struct text_message * message, | ||
484 | int pos) | ||
485 | { | ||
486 | int i; | ||
487 | luaL_checktype(L, pos, LUA_TTABLE); | ||
488 | int n = luaL_getn(L, pos); | ||
489 | const char **lines = (const char**) dlmalloc(n * sizeof(const char*)); | ||
490 | for(i=1; i<=n; i++) | ||
491 | { | ||
492 | lua_rawgeti(L, pos, i); | ||
493 | lines[i-1] = luaL_checkstring(L, -1); | ||
494 | lua_pop(L, 1); | ||
495 | } | ||
496 | message->message_lines = lines; | ||
497 | message->nb_lines = n; | ||
498 | } | ||
499 | |||
500 | RB_WRAP(gui_syncyesno_run) | ||
501 | { | ||
502 | struct text_message main_message, yes_message, no_message; | ||
503 | struct text_message *yes = NULL, *no = NULL; | ||
504 | |||
505 | fill_text_message(L, &main_message, 1); | ||
506 | if(!lua_isnoneornil(L, 2)) | ||
507 | fill_text_message(L, (yes = &yes_message), 2); | ||
508 | if(!lua_isnoneornil(L, 3)) | ||
509 | fill_text_message(L, (no = &no_message), 3); | ||
510 | |||
511 | enum yesno_res result = rb->gui_syncyesno_run(&main_message, yes, no); | ||
512 | |||
513 | dlfree(main_message.message_lines); | ||
514 | if(yes) | ||
515 | dlfree(yes_message.message_lines); | ||
516 | if(no) | ||
517 | dlfree(no_message.message_lines); | ||
518 | |||
519 | lua_pushinteger(L, result); | ||
520 | return 1; | ||
521 | } | ||
522 | |||
483 | #define R(NAME) {#NAME, rock_##NAME} | 523 | #define R(NAME) {#NAME, rock_##NAME} |
484 | static const luaL_Reg rocklib[] = | 524 | static const luaL_Reg rocklib[] = |
485 | { | 525 | { |
@@ -518,6 +558,7 @@ static const luaL_Reg rocklib[] = | |||
518 | R(set_viewport), | 558 | R(set_viewport), |
519 | R(clear_viewport), | 559 | R(clear_viewport), |
520 | R(current_path), | 560 | R(current_path), |
561 | R(gui_syncyesno_run), | ||
521 | 562 | ||
522 | {"new_image", rli_new}, | 563 | {"new_image", rli_new}, |
523 | 564 | ||