Prepare new maemo release
[maemo-rb.git] / apps / plugins / lua / rocklib.c
blobd89f48fa39a446f7d8d481338b92063523ba9928
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 Dan Everton (safetydan)
11 * Copyright (C) 2009 Maurus Cuelenaere
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
23 #define lrocklib_c
24 #define LUA_LIB
26 #include "lua.h"
28 #include "lauxlib.h"
29 #include "rocklib.h"
30 #include "lib/helper.h"
31 #include "lib/pluginlib_actions.h"
34 * http://www.lua.org/manual/5.1/manual.html#lua_CFunction
36 * In order to communicate properly with Lua, a C function must use the following protocol,
37 * which defines the way parameters and results are passed: a C function receives its arguments
38 * from Lua in its stack in direct order (the first argument is pushed first). To return values to Lua,
39 * a C function just pushes them onto the stack, in direct order (the first result is pushed first),
40 * and returns the number of results. Any other value in the stack below the results will be properly
41 * discarded by Lua. Like a Lua function, a C function called by Lua can also return many results.
43 * When porting new functions, don't forget to check rocklib_aux.pl whether it automatically creates
44 * wrappers for the function and if so, add the function names to @forbidden_functions. This is to
45 * prevent namespace collisions and adding duplicate wrappers.
50 * -----------------------------
52 * Rockbox Lua image wrapper
54 * -----------------------------
57 #define ROCKLUA_IMAGE "rb.image"
58 struct rocklua_image
60 int width;
61 int height;
62 fb_data *data;
63 fb_data dummy[1][1];
66 static void rli_wrap(lua_State *L, fb_data *src, int width, int height)
68 struct rocklua_image *a = (struct rocklua_image *)lua_newuserdata(L, sizeof(struct rocklua_image));
70 luaL_getmetatable(L, ROCKLUA_IMAGE);
71 lua_setmetatable(L, -2);
73 a->width = width;
74 a->height = height;
75 a->data = src;
78 static fb_data* rli_alloc(lua_State *L, int width, int height)
80 size_t nbytes = sizeof(struct rocklua_image) + ((width*height) - 1) * sizeof(fb_data);
81 struct rocklua_image *a = (struct rocklua_image *)lua_newuserdata(L, nbytes);
83 luaL_getmetatable(L, ROCKLUA_IMAGE);
84 lua_setmetatable(L, -2);
86 a->width = width;
87 a->height = height;
88 a->data = &a->dummy[0][0];
90 return a->data;
93 static int rli_new(lua_State *L)
95 int width = luaL_checkint(L, 1);
96 int height = luaL_checkint(L, 2);
98 rli_alloc(L, width, height);
100 return 1;
103 static struct rocklua_image* rli_checktype(lua_State *L, int arg)
105 void *ud = luaL_checkudata(L, arg, ROCKLUA_IMAGE);
106 luaL_argcheck(L, ud != NULL, arg, "'" ROCKLUA_IMAGE "' expected");
107 return (struct rocklua_image*) ud;
110 static int rli_width(lua_State *L)
112 struct rocklua_image *a = rli_checktype(L, 1);
113 lua_pushnumber(L, a->width);
114 return 1;
117 static int rli_height(lua_State *L)
119 struct rocklua_image *a = rli_checktype(L, 1);
120 lua_pushnumber(L, a->height);
121 return 1;
124 static fb_data* rli_element(lua_State *L)
126 struct rocklua_image *a = rli_checktype(L, 1);
127 int x = luaL_checkint(L, 2);
128 int y = luaL_checkint(L, 3);
130 luaL_argcheck(L, 1 <= x && x <= a->width, 2,
131 "index out of range");
132 luaL_argcheck(L, 1 <= y && y <= a->height, 3,
133 "index out of range");
135 /* return element address */
136 return &a->data[a->width * (y - 1) + (x - 1)];
139 static int rli_set(lua_State *L)
141 fb_data newvalue = (fb_data) luaL_checknumber(L, 4);
142 *rli_element(L) = newvalue;
143 return 0;
146 static int rli_get(lua_State *L)
148 lua_pushnumber(L, *rli_element(L));
149 return 1;
152 static int rli_tostring(lua_State *L)
154 struct rocklua_image *a = rli_checktype(L, 1);
155 lua_pushfstring(L, ROCKLUA_IMAGE ": %dx%d", a->width, a->height);
156 return 1;
159 static const struct luaL_reg rli_lib [] =
161 {"__tostring", rli_tostring},
162 {"set", rli_set},
163 {"get", rli_get},
164 {"width", rli_width},
165 {"height", rli_height},
166 {NULL, NULL}
169 static inline void rli_init(lua_State *L)
171 luaL_newmetatable(L, ROCKLUA_IMAGE);
173 lua_pushstring(L, "__index");
174 lua_pushvalue(L, -2); /* pushes the metatable */
175 lua_settable(L, -3); /* metatable.__index = metatable */
177 luaL_register(L, NULL, rli_lib);
181 * -----------------------------
183 * Rockbox wrappers start here!
185 * -----------------------------
188 #define RB_WRAP(M) static int rock_##M(lua_State UNUSED_ATTR *L)
189 #define SIMPLE_VOID_WRAPPER(func) RB_WRAP(func) { (void)L; func(); return 0; }
191 /* Helper function for opt_viewport */
192 static void check_tablevalue(lua_State *L, const char* key, int tablepos, void* res, bool unsigned_val)
194 lua_getfield(L, tablepos, key); /* Find table[key] */
196 if(!lua_isnoneornil(L, -1))
198 if(unsigned_val)
199 *(unsigned*)res = luaL_checkint(L, -1);
200 else
201 *(int*)res = luaL_checkint(L, -1);
204 lua_pop(L, 1); /* Pop the value off the stack */
207 static struct viewport* opt_viewport(lua_State *L, int narg, struct viewport* alt)
209 if(lua_isnoneornil(L, narg))
210 return alt;
212 int tablepos = lua_gettop(L);
213 struct viewport *vp;
215 lua_getfield(L, tablepos, "vp"); /* get table['vp'] */
216 if(lua_isnoneornil(L, -1))
218 lua_pop(L, 1); /* Pop nil off stack */
220 vp = (struct viewport*) lua_newuserdata(L, sizeof(struct viewport)); /* Allocate memory and push it as udata on the stack */
221 memset(vp, 0, sizeof(struct viewport)); /* Init viewport values to 0 */
222 lua_setfield(L, tablepos, "vp"); /* table['vp'] = vp (pops value off the stack) */
224 else
226 vp = (struct viewport*) lua_touserdata(L, -1); /* Reuse viewport struct */
227 lua_pop(L, 1); /* We don't need the value on stack */
230 luaL_checktype(L, narg, LUA_TTABLE);
232 check_tablevalue(L, "x", tablepos, &vp->x, false);
233 check_tablevalue(L, "y", tablepos, &vp->y, false);
234 check_tablevalue(L, "width", tablepos, &vp->width, false);
235 check_tablevalue(L, "height", tablepos, &vp->height, false);
236 #ifdef HAVE_LCD_BITMAP
237 check_tablevalue(L, "font", tablepos, &vp->font, false);
238 check_tablevalue(L, "drawmode", tablepos, &vp->drawmode, false);
239 #endif
240 #if LCD_DEPTH > 1
241 check_tablevalue(L, "fg_pattern", tablepos, &vp->fg_pattern, true);
242 check_tablevalue(L, "bg_pattern", tablepos, &vp->bg_pattern, true);
243 #ifdef HAVE_LCD_COLOR
244 check_tablevalue(L, "lss_pattern", tablepos, &vp->lss_pattern, true);
245 check_tablevalue(L, "lse_pattern", tablepos, &vp->lse_pattern, true);
246 check_tablevalue(L, "lst_pattern", tablepos, &vp->lst_pattern, true);
247 #endif
248 #endif
250 return vp;
253 RB_WRAP(set_viewport)
255 struct viewport *vp = opt_viewport(L, 1, NULL);
256 int screen = luaL_optint(L, 2, SCREEN_MAIN);
257 rb->screens[screen]->set_viewport(vp);
258 return 0;
261 RB_WRAP(clear_viewport)
263 int screen = luaL_optint(L, 1, SCREEN_MAIN);
264 rb->screens[screen]->clear_viewport();
265 return 0;
268 #ifdef HAVE_LCD_BITMAP
269 RB_WRAP(lcd_framebuffer)
271 rli_wrap(L, rb->lcd_framebuffer, LCD_WIDTH, LCD_HEIGHT);
272 return 1;
275 RB_WRAP(lcd_mono_bitmap_part)
277 struct rocklua_image *src = rli_checktype(L, 1);
278 int src_x = luaL_checkint(L, 2);
279 int src_y = luaL_checkint(L, 3);
280 int stride = luaL_checkint(L, 4);
281 int x = luaL_checkint(L, 5);
282 int y = luaL_checkint(L, 6);
283 int width = luaL_checkint(L, 7);
284 int height = luaL_checkint(L, 8);
285 int screen = luaL_optint(L, 9, SCREEN_MAIN);
287 rb->screens[screen]->mono_bitmap_part((const unsigned char *)src->data, src_x, src_y, stride, x, y, width, height);
288 return 0;
291 RB_WRAP(lcd_mono_bitmap)
293 struct rocklua_image *src = rli_checktype(L, 1);
294 int x = luaL_checkint(L, 2);
295 int y = luaL_checkint(L, 3);
296 int width = luaL_checkint(L, 4);
297 int height = luaL_checkint(L, 5);
298 int screen = luaL_optint(L, 6, SCREEN_MAIN);
300 rb->screens[screen]->mono_bitmap((const unsigned char *)src->data, x, y, width, height);
301 return 0;
304 #if LCD_DEPTH > 1
305 RB_WRAP(lcd_bitmap_part)
307 struct rocklua_image *src = rli_checktype(L, 1);
308 int src_x = luaL_checkint(L, 2);
309 int src_y = luaL_checkint(L, 3);
310 int stride = luaL_checkint(L, 4);
311 int x = luaL_checkint(L, 5);
312 int y = luaL_checkint(L, 6);
313 int width = luaL_checkint(L, 7);
314 int height = luaL_checkint(L, 8);
315 int screen = luaL_optint(L, 9, SCREEN_MAIN);
317 rb->screens[screen]->bitmap_part(src->data, src_x, src_y, stride, x, y, width, height);
318 return 0;
321 RB_WRAP(lcd_bitmap)
323 struct rocklua_image *src = rli_checktype(L, 1);
324 int x = luaL_checkint(L, 2);
325 int y = luaL_checkint(L, 3);
326 int width = luaL_checkint(L, 4);
327 int height = luaL_checkint(L, 5);
328 int screen = luaL_optint(L, 6, SCREEN_MAIN);
330 rb->screens[screen]->bitmap(src->data, x, y, width, height);
331 return 0;
334 RB_WRAP(lcd_get_backdrop)
336 fb_data* backdrop = rb->lcd_get_backdrop();
337 if(backdrop == NULL)
338 lua_pushnil(L);
339 else
340 rli_wrap(L, backdrop, LCD_WIDTH, LCD_HEIGHT);
342 return 1;
344 #endif /* LCD_DEPTH > 1 */
346 #if LCD_DEPTH == 16
347 RB_WRAP(lcd_bitmap_transparent_part)
349 struct rocklua_image *src = rli_checktype(L, 1);
350 int src_x = luaL_checkint(L, 2);
351 int src_y = luaL_checkint(L, 3);
352 int stride = luaL_checkint(L, 4);
353 int x = luaL_checkint(L, 5);
354 int y = luaL_checkint(L, 6);
355 int width = luaL_checkint(L, 7);
356 int height = luaL_checkint(L, 8);
357 int screen = luaL_optint(L, 9, SCREEN_MAIN);
359 rb->screens[screen]->transparent_bitmap_part(src->data, src_x, src_y, stride, x, y, width, height);
360 return 0;
363 RB_WRAP(lcd_bitmap_transparent)
365 struct rocklua_image *src = rli_checktype(L, 1);
366 int x = luaL_checkint(L, 2);
367 int y = luaL_checkint(L, 3);
368 int width = luaL_checkint(L, 4);
369 int height = luaL_checkint(L, 5);
370 int screen = luaL_optint(L, 6, SCREEN_MAIN);
372 rb->screens[screen]->transparent_bitmap(src->data, x, y, width, height);
373 return 0;
375 #endif /* LCD_DEPTH == 16 */
377 #endif /* defined(LCD_BITMAP) */
379 RB_WRAP(current_tick)
381 lua_pushinteger(L, *rb->current_tick);
382 return 1;
385 #ifdef HAVE_TOUCHSCREEN
386 RB_WRAP(action_get_touchscreen_press)
388 short x, y;
389 int result = rb->action_get_touchscreen_press(&x, &y);
391 lua_pushinteger(L, result);
392 lua_pushinteger(L, x);
393 lua_pushinteger(L, y);
394 return 3;
396 #endif
398 RB_WRAP(kbd_input)
400 luaL_Buffer b;
401 luaL_buffinit(L, &b);
403 const char *input = luaL_optstring(L, 1, NULL);
404 char *buffer = luaL_prepbuffer(&b);
406 if(input != NULL)
407 rb->strlcpy(buffer, input, LUAL_BUFFERSIZE);
408 else
409 buffer[0] = '\0';
411 if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE))
413 luaL_addsize(&b, strlen(buffer));
414 luaL_pushresult(&b);
416 else
417 lua_pushnil(L);
419 return 1;
422 #ifdef HAVE_TOUCHSCREEN
423 RB_WRAP(touchscreen_set_mode)
425 enum touchscreen_mode mode = luaL_checkint(L, 1);
426 rb->touchscreen_set_mode(mode);
427 return 0;
429 RB_WRAP(touchscreen_get_mode)
431 lua_pushinteger(L, rb->touchscreen_get_mode());
432 return 1;
434 #endif
436 RB_WRAP(font_getstringsize)
438 const unsigned char* str = luaL_checkstring(L, 1);
439 int fontnumber = luaL_checkint(L, 2);
440 int w, h;
442 if (fontnumber == FONT_UI)
443 fontnumber = rb->global_status->font_id[SCREEN_MAIN];
444 else
445 fontnumber = FONT_SYSFIXED;
447 int result = rb->font_getstringsize(str, &w, &h, fontnumber);
448 lua_pushinteger(L, result);
449 lua_pushinteger(L, w);
450 lua_pushinteger(L, h);
452 return 3;
455 #ifdef HAVE_LCD_COLOR
456 RB_WRAP(lcd_rgbpack)
458 int r = luaL_checkint(L, 1);
459 int g = luaL_checkint(L, 2);
460 int b = luaL_checkint(L, 3);
461 int result = LCD_RGBPACK(r, g, b);
462 lua_pushinteger(L, result);
463 return 1;
466 RB_WRAP(lcd_rgbunpack)
468 int rgb = luaL_checkint(L, 1);
469 lua_pushinteger(L, RGB_UNPACK_RED(rgb));
470 lua_pushinteger(L, RGB_UNPACK_GREEN(rgb));
471 lua_pushinteger(L, RGB_UNPACK_BLUE(rgb));
472 return 3;
474 #endif
476 RB_WRAP(read_bmp_file)
478 struct bitmap bm;
479 const char* filename = luaL_checkstring(L, 1);
480 bool dither = luaL_optboolean(L, 2, true);
481 bool transparent = luaL_optboolean(L, 3, false);
482 int format = FORMAT_NATIVE;
484 if(dither)
485 format |= FORMAT_DITHER;
487 if(transparent)
488 format |= FORMAT_TRANSPARENT;
490 int result = rb->read_bmp_file(filename, &bm, 0, format | FORMAT_RETURN_SIZE, NULL);
492 if(result > 0)
494 bm.data = (unsigned char*) rli_alloc(L, bm.width, bm.height);
495 if(rb->read_bmp_file(filename, &bm, result, format, NULL) < 0)
497 /* Error occured, drop newly allocated image from stack */
498 lua_pop(L, 1);
499 lua_pushnil(L);
502 else
503 lua_pushnil(L);
505 return 1;
508 RB_WRAP(current_path)
510 const char *current_path = get_current_path(L, 1);
511 if(current_path != NULL)
512 lua_pushstring(L, current_path);
513 else
514 lua_pushnil(L);
516 return 1;
519 static void fill_text_message(lua_State *L, struct text_message * message,
520 int pos)
522 int i;
523 luaL_checktype(L, pos, LUA_TTABLE);
524 int n = luaL_getn(L, pos);
525 const char **lines = (const char**) dlmalloc(n * sizeof(const char*));
526 if(lines == NULL)
527 luaL_error(L, "Can't allocate %d bytes!", n * sizeof(const char*));
528 for(i=1; i<=n; i++)
530 lua_rawgeti(L, pos, i);
531 lines[i-1] = luaL_checkstring(L, -1);
532 lua_pop(L, 1);
534 message->message_lines = lines;
535 message->nb_lines = n;
538 RB_WRAP(gui_syncyesno_run)
540 struct text_message main_message, yes_message, no_message;
541 struct text_message *yes = NULL, *no = NULL;
543 fill_text_message(L, &main_message, 1);
544 if(!lua_isnoneornil(L, 2))
545 fill_text_message(L, (yes = &yes_message), 2);
546 if(!lua_isnoneornil(L, 3))
547 fill_text_message(L, (no = &no_message), 3);
549 enum yesno_res result = rb->gui_syncyesno_run(&main_message, yes, no);
551 dlfree(main_message.message_lines);
552 if(yes)
553 dlfree(yes_message.message_lines);
554 if(no)
555 dlfree(no_message.message_lines);
557 lua_pushinteger(L, result);
558 return 1;
561 RB_WRAP(do_menu)
563 struct menu_callback_with_desc menu_desc = {NULL, NULL, Icon_NOICON};
564 struct menu_item_ex menu = {MT_RETURN_ID | MENU_HAS_DESC, {.strings = NULL},
565 {.callback_and_desc = &menu_desc}};
566 int i, n, start_selected;
567 const char **items, *title;
569 title = luaL_checkstring(L, 1);
570 luaL_checktype(L, 2, LUA_TTABLE);
571 start_selected = luaL_optint(L, 3, 0);
573 n = luaL_getn(L, 2);
574 items = (const char**) dlmalloc(n * sizeof(const char*));
575 if(items == NULL)
576 luaL_error(L, "Can't allocate %d bytes!", n * sizeof(const char*));
577 for(i=1; i<=n; i++)
579 lua_rawgeti(L, 2, i); /* Push item on the stack */
580 items[i-1] = luaL_checkstring(L, -1);
581 lua_pop(L, 1); /* Pop it */
584 menu.strings = items;
585 menu.flags |= MENU_ITEM_COUNT(n);
586 menu_desc.desc = (unsigned char*) title;
588 int result = rb->do_menu(&menu, &start_selected, NULL, false);
590 dlfree(items);
592 lua_pushinteger(L, result);
593 return 1;
596 RB_WRAP(playlist_sync)
598 /* just pass NULL to work with the current playlist */
599 rb->playlist_sync(NULL);
600 return 1;
603 RB_WRAP(playlist_remove_all_tracks)
605 /* just pass NULL to work with the current playlist */
606 int result = rb->playlist_remove_all_tracks(NULL);
607 lua_pushinteger(L, result);
608 return 1;
611 RB_WRAP(playlist_insert_track)
613 const char *filename;
614 int position, queue, sync;
616 /* for now don't take a playlist_info pointer, but just pass NULL to use
617 the current playlist. If this changes later, all the other
618 parameters can be shifted back. */
619 filename = luaL_checkstring(L, 1); /* only required parameter */
620 position = luaL_optint(L, 2, PLAYLIST_INSERT);
621 queue = lua_toboolean(L, 3); /* default to false */
622 sync = lua_toboolean(L, 4); /* default to false */
624 int result = rb->playlist_insert_track(NULL, filename, position,
625 queue, sync);
627 lua_pushinteger(L, result);
628 return 1;
631 RB_WRAP(playlist_insert_directory)
633 const char* dirname;
634 int position, queue, recurse;
636 /* just like in playlist_insert_track, only works with current playlist. */
637 dirname = luaL_checkstring(L, 1); /* only required parameter */
638 position = luaL_optint(L, 2, PLAYLIST_INSERT);
639 queue = lua_toboolean(L, 3); /* default to false */
640 recurse = lua_toboolean(L, 4); /* default to false */
642 int result = rb->playlist_insert_directory(NULL, dirname, position,
643 queue, recurse);
645 lua_pushinteger(L, result);
646 return 1;
649 SIMPLE_VOID_WRAPPER(backlight_force_on);
650 SIMPLE_VOID_WRAPPER(backlight_use_settings);
651 #ifdef HAVE_REMOTE_LCD
652 SIMPLE_VOID_WRAPPER(remote_backlight_force_on);
653 SIMPLE_VOID_WRAPPER(remote_backlight_use_settings);
654 #endif
655 #ifdef HAVE_BUTTON_LIGHT
656 SIMPLE_VOID_WRAPPER(buttonlight_force_on);
657 SIMPLE_VOID_WRAPPER(buttonlight_use_settings);
658 #endif
659 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
660 RB_WRAP(backlight_brightness_set)
662 int brightness = luaL_checkint(L, 1);
663 backlight_brightness_set(brightness);
665 return 0;
667 SIMPLE_VOID_WRAPPER(backlight_brightness_use_setting);
668 #endif
670 RB_WRAP(get_plugin_action)
672 static const struct button_mapping *m1[] = { pla_main_ctx };
673 int timeout = luaL_checkint(L, 1);
674 int btn;
675 #ifdef HAVE_REMOTE_LCD
676 static const struct button_mapping *m2[] = { pla_main_ctx, pla_remote_ctx };
677 bool with_remote = luaL_optint(L, 2, 0);
678 if (with_remote)
679 btn = pluginlib_getaction(timeout, m2, 2);
680 else
681 #endif
682 btn = pluginlib_getaction(timeout, m1, 1);
684 lua_pushinteger(L, btn);
685 return 1;
688 #define R(NAME) {#NAME, rock_##NAME}
689 static const luaL_Reg rocklib[] =
691 /* Graphics */
692 #ifdef HAVE_LCD_BITMAP
693 R(lcd_framebuffer),
694 R(lcd_mono_bitmap_part),
695 R(lcd_mono_bitmap),
696 #if LCD_DEPTH > 1
697 R(lcd_get_backdrop),
698 R(lcd_bitmap_part),
699 R(lcd_bitmap),
700 #endif
701 #if LCD_DEPTH == 16
702 R(lcd_bitmap_transparent_part),
703 R(lcd_bitmap_transparent),
704 #endif
705 #endif
706 #ifdef HAVE_LCD_COLOR
707 R(lcd_rgbpack),
708 R(lcd_rgbunpack),
709 #endif
711 /* Kernel */
712 R(current_tick),
714 /* Buttons */
715 #ifdef HAVE_TOUCHSCREEN
716 R(action_get_touchscreen_press),
717 R(touchscreen_set_mode),
718 R(touchscreen_get_mode),
719 #endif
720 R(kbd_input),
722 R(font_getstringsize),
723 R(read_bmp_file),
724 R(set_viewport),
725 R(clear_viewport),
726 R(current_path),
727 R(gui_syncyesno_run),
728 R(playlist_sync),
729 R(playlist_remove_all_tracks),
730 R(playlist_insert_track),
731 R(playlist_insert_directory),
732 R(do_menu),
734 /* Backlight helper */
735 R(backlight_force_on),
736 R(backlight_use_settings),
737 #ifdef HAVE_REMOTE_LCD
738 R(remote_backlight_force_on),
739 R(remote_backlight_use_settings),
740 #endif
741 #ifdef HAVE_BUTTON_LIGHT
742 R(buttonlight_force_on),
743 R(buttonlight_use_settings),
744 #endif
745 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
746 R(backlight_brightness_set),
747 R(backlight_brightness_use_setting),
748 #endif
749 R(get_plugin_action),
751 {"new_image", rli_new},
753 {NULL, NULL}
755 #undef R
756 extern const luaL_Reg rocklib_aux[];
759 #define RB_CONSTANT(x) lua_pushinteger(L, x); lua_setfield(L, -2, #x);
760 #define RB_STRING_CONSTANT(x) lua_pushstring(L, x); lua_setfield(L, -2, #x);
762 ** Open Rockbox library
764 LUALIB_API int luaopen_rock(lua_State *L)
766 luaL_register(L, LUA_ROCKLIBNAME, rocklib);
767 luaL_register(L, LUA_ROCKLIBNAME, rocklib_aux);
769 RB_CONSTANT(HZ);
771 RB_CONSTANT(LCD_WIDTH);
772 RB_CONSTANT(LCD_HEIGHT);
773 RB_CONSTANT(LCD_DEPTH);
775 RB_CONSTANT(FONT_SYSFIXED);
776 RB_CONSTANT(FONT_UI);
778 RB_CONSTANT(PLAYLIST_PREPEND);
779 RB_CONSTANT(PLAYLIST_INSERT);
780 RB_CONSTANT(PLAYLIST_INSERT_LAST);
781 RB_CONSTANT(PLAYLIST_INSERT_FIRST);
782 RB_CONSTANT(PLAYLIST_INSERT_SHUFFLED);
783 RB_CONSTANT(PLAYLIST_REPLACE);
784 RB_CONSTANT(PLAYLIST_INSERT_LAST_SHUFFLED);
786 #ifdef HAVE_TOUCHSCREEN
787 RB_CONSTANT(TOUCHSCREEN_POINT);
788 RB_CONSTANT(TOUCHSCREEN_BUTTON);
789 #endif
791 RB_CONSTANT(SCREEN_MAIN);
792 #ifdef HAVE_REMOTE_LCD
793 RB_CONSTANT(SCREEN_REMOTE);
794 #endif
796 /* some useful paths constants */
797 RB_STRING_CONSTANT(ROCKBOX_DIR);
798 RB_STRING_CONSTANT(HOME_DIR);
799 RB_STRING_CONSTANT(PLUGIN_DIR);
800 RB_STRING_CONSTANT(PLUGIN_APPS_DATA_DIR);
801 RB_STRING_CONSTANT(PLUGIN_GAMES_DATA_DIR);
802 RB_STRING_CONSTANT(PLUGIN_DATA_DIR);
803 RB_STRING_CONSTANT(VIEWERS_DATA_DIR);
805 rli_init(L);
807 return 1;