summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rocklib.c
diff options
context:
space:
mode:
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 80124d2165..c9242d99bd 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -56,66 +56,6 @@
56#define RB_WRAP(func) static int rock_##func(lua_State UNUSED_ATTR *L) 56#define RB_WRAP(func) static int rock_##func(lua_State UNUSED_ATTR *L)
57#define SIMPLE_VOID_WRAPPER(func) RB_WRAP(func) { (void)L; func(); return 0; } 57#define SIMPLE_VOID_WRAPPER(func) RB_WRAP(func) { (void)L; func(); return 0; }
58 58
59/* Helper function for opt_viewport */
60static void check_tablevalue(lua_State *L,
61 const char* key,
62 int tablepos,
63 void* res,
64 bool is_unsigned)
65{
66 lua_getfield(L, tablepos, key); /* Find table[key] */
67
68 int val = lua_tointeger(L, -1);
69
70 if(is_unsigned)
71 *(unsigned*)res = (unsigned) val;
72 else
73 *(int*)res = val;
74
75 lua_pop(L, 1); /* Pop the value off the stack */
76}
77
78static inline struct viewport* opt_viewport(lua_State *L,
79 int narg,
80 struct viewport* vp,
81 struct viewport* alt)
82{
83 if(lua_isnoneornil(L, narg))
84 return alt;
85
86 luaL_checktype(L, narg, LUA_TTABLE);
87
88 check_tablevalue(L, "x", narg, &vp->x, false);
89 check_tablevalue(L, "y", narg, &vp->y, false);
90 check_tablevalue(L, "width", narg, &vp->width, false);
91 check_tablevalue(L, "height", narg, &vp->height, false);
92#ifdef HAVE_LCD_BITMAP
93 check_tablevalue(L, "font", narg, &vp->font, false);
94 check_tablevalue(L, "drawmode", narg, &vp->drawmode, false);
95#endif
96#if LCD_DEPTH > 1
97 check_tablevalue(L, "fg_pattern", narg, &vp->fg_pattern, true);
98 check_tablevalue(L, "bg_pattern", narg, &vp->bg_pattern, true);
99#endif
100
101 return vp;
102}
103
104RB_WRAP(set_viewport)
105{
106 static struct viewport vp;
107 int screen = luaL_optint(L, 2, SCREEN_MAIN);
108 rb->screens[screen]->set_viewport(opt_viewport(L, 1, &vp, NULL));
109 return 0;
110}
111
112RB_WRAP(clear_viewport)
113{
114 int screen = luaL_optint(L, 1, SCREEN_MAIN);
115 rb->screens[screen]->clear_viewport();
116 return 0;
117}
118
119RB_WRAP(current_tick) 59RB_WRAP(current_tick)
120{ 60{
121 lua_pushinteger(L, *rb->current_tick); 61 lua_pushinteger(L, *rb->current_tick);
@@ -172,25 +112,6 @@ RB_WRAP(touchscreen_get_mode)
172} 112}
173#endif 113#endif
174 114
175RB_WRAP(font_getstringsize)
176{
177 const unsigned char* str = luaL_checkstring(L, 1);
178 int fontnumber = luaL_checkint(L, 2);
179 int w, h;
180
181 if (fontnumber == FONT_UI)
182 fontnumber = rb->global_status->font_id[SCREEN_MAIN];
183 else
184 fontnumber = FONT_SYSFIXED;
185
186 int result = rb->font_getstringsize(str, &w, &h, fontnumber);
187 lua_pushinteger(L, result);
188 lua_pushinteger(L, w);
189 lua_pushinteger(L, h);
190
191 return 3;
192}
193
194RB_WRAP(current_path) 115RB_WRAP(current_path)
195{ 116{
196 return get_current_path(L, 1); 117 return get_current_path(L, 1);
@@ -507,9 +428,6 @@ static const luaL_Reg rocklib[] =
507 428
508 RB_FUNC(kbd_input), 429 RB_FUNC(kbd_input),
509 430
510 RB_FUNC(font_getstringsize),
511 RB_FUNC(set_viewport),
512 RB_FUNC(clear_viewport),
513 RB_FUNC(current_path), 431 RB_FUNC(current_path),
514 RB_FUNC(gui_syncyesno_run), 432 RB_FUNC(gui_syncyesno_run),
515 RB_FUNC(do_menu), 433 RB_FUNC(do_menu),
@@ -563,6 +481,11 @@ LUALIB_API int luaopen_rock(lua_State *L)
563 RB_CONSTANT(LCD_DEPTH), 481 RB_CONSTANT(LCD_DEPTH),
564 RB_CONSTANT(LCD_HEIGHT), 482 RB_CONSTANT(LCD_HEIGHT),
565 RB_CONSTANT(LCD_WIDTH), 483 RB_CONSTANT(LCD_WIDTH),
484#ifdef HAVE_REMOTE_LCD
485 RB_CONSTANT(LCD_REMOTE_DEPTH),
486 RB_CONSTANT(LCD_REMOTE_HEIGHT),
487 RB_CONSTANT(LCD_REMOTE_WIDTH),
488#endif
566 489
567 RB_CONSTANT(FONT_SYSFIXED), 490 RB_CONSTANT(FONT_SYSFIXED),
568 RB_CONSTANT(FONT_UI), 491 RB_CONSTANT(FONT_UI),