summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rocklib.c
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-10-27 06:24:27 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2018-10-30 04:16:23 +0100
commitdf8233e4abbd0d626158abc5388957cc28b06c50 (patch)
tree3b6c151b8dba5201673dd8ae2842350822243cde /apps/plugins/lua/rocklib.c
parent80352c2c2d7ff005e0ad63e1b56d1f6ff9af81d8 (diff)
downloadrockbox-df8233e4abbd0d626158abc5388957cc28b06c50.zip
rockbox-df8233e4abbd0d626158abc5388957cc28b06c50.tar.gz
rockbox-df8233e4abbd0d626158abc5388957cc28b06c50.tar.bz2
rockbox-df8233e4abbd0d626158abc5388957cc28b06c50.tar.xz
Lua expand multiple screen support
Some of the lcd functions had support for multiple screens but this wasn't very safe since the screen number wasn't bounded within the screens[] array This adds support for all the lcd functions along with checking that screen# is bounded properly, adds around 600 bytes to devices with a remote screen devices without a remote screen lock to SCREEN_MAIN Change-Id: I618bbc7b3919c7b0ff375fb2d71949d7cab43c87
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r--apps/plugins/lua/rocklib.c87
1 files changed, 5 insertions, 82 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 80124d2..c9242d9 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -56,66 +56,6 @@
#define RB_WRAP(func) static int rock_##func(lua_State UNUSED_ATTR *L)
#define SIMPLE_VOID_WRAPPER(func) RB_WRAP(func) { (void)L; func(); return 0; }
-/* Helper function for opt_viewport */
-static void check_tablevalue(lua_State *L,
- const char* key,
- int tablepos,
- void* res,
- bool is_unsigned)
-{
- lua_getfield(L, tablepos, key); /* Find table[key] */
-
- int val = lua_tointeger(L, -1);
-
- if(is_unsigned)
- *(unsigned*)res = (unsigned) val;
- else
- *(int*)res = val;
-
- lua_pop(L, 1); /* Pop the value off the stack */
-}
-
-static inline struct viewport* opt_viewport(lua_State *L,
- int narg,
- struct viewport* vp,
- struct viewport* alt)
-{
- if(lua_isnoneornil(L, narg))
- return alt;
-
- luaL_checktype(L, narg, LUA_TTABLE);
-
- check_tablevalue(L, "x", narg, &vp->x, false);
- check_tablevalue(L, "y", narg, &vp->y, false);
- check_tablevalue(L, "width", narg, &vp->width, false);
- check_tablevalue(L, "height", narg, &vp->height, false);
-#ifdef HAVE_LCD_BITMAP
- check_tablevalue(L, "font", narg, &vp->font, false);
- check_tablevalue(L, "drawmode", narg, &vp->drawmode, false);
-#endif
-#if LCD_DEPTH > 1
- check_tablevalue(L, "fg_pattern", narg, &vp->fg_pattern, true);
- check_tablevalue(L, "bg_pattern", narg, &vp->bg_pattern, true);
-#endif
-
- return vp;
-}
-
-RB_WRAP(set_viewport)
-{
- static struct viewport vp;
- int screen = luaL_optint(L, 2, SCREEN_MAIN);
- rb->screens[screen]->set_viewport(opt_viewport(L, 1, &vp, NULL));
- return 0;
-}
-
-RB_WRAP(clear_viewport)
-{
- int screen = luaL_optint(L, 1, SCREEN_MAIN);
- rb->screens[screen]->clear_viewport();
- return 0;
-}
-
RB_WRAP(current_tick)
{
lua_pushinteger(L, *rb->current_tick);
@@ -172,25 +112,6 @@ RB_WRAP(touchscreen_get_mode)
}
#endif
-RB_WRAP(font_getstringsize)
-{
- const unsigned char* str = luaL_checkstring(L, 1);
- int fontnumber = luaL_checkint(L, 2);
- int w, h;
-
- if (fontnumber == FONT_UI)
- fontnumber = rb->global_status->font_id[SCREEN_MAIN];
- else
- fontnumber = FONT_SYSFIXED;
-
- int result = rb->font_getstringsize(str, &w, &h, fontnumber);
- lua_pushinteger(L, result);
- lua_pushinteger(L, w);
- lua_pushinteger(L, h);
-
- return 3;
-}
-
RB_WRAP(current_path)
{
return get_current_path(L, 1);
@@ -507,9 +428,6 @@ static const luaL_Reg rocklib[] =
RB_FUNC(kbd_input),
- RB_FUNC(font_getstringsize),
- RB_FUNC(set_viewport),
- RB_FUNC(clear_viewport),
RB_FUNC(current_path),
RB_FUNC(gui_syncyesno_run),
RB_FUNC(do_menu),
@@ -563,6 +481,11 @@ LUALIB_API int luaopen_rock(lua_State *L)
RB_CONSTANT(LCD_DEPTH),
RB_CONSTANT(LCD_HEIGHT),
RB_CONSTANT(LCD_WIDTH),
+#ifdef HAVE_REMOTE_LCD
+ RB_CONSTANT(LCD_REMOTE_DEPTH),
+ RB_CONSTANT(LCD_REMOTE_HEIGHT),
+ RB_CONSTANT(LCD_REMOTE_WIDTH),
+#endif
RB_CONSTANT(FONT_SYSFIXED),
RB_CONSTANT(FONT_UI),