Lua:
[kugel-rb.git] / apps / plugins / lua / rocklib.c
blob6da57d154ed0d19cadc605256a98c9209a6069ae
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"
32 * http://www.lua.org/manual/5.1/manual.html#lua_CFunction
34 * In order to communicate properly with Lua, a C function must use the following protocol,
35 * which defines the way parameters and results are passed: a C function receives its arguments
36 * from Lua in its stack in direct order (the first argument is pushed first). To return values to Lua,
37 * a C function just pushes them onto the stack, in direct order (the first result is pushed first),
38 * and returns the number of results. Any other value in the stack below the results will be properly
39 * discarded by Lua. Like a Lua function, a C function called by Lua can also return many results.
44 * -----------------------------
46 * Rockbox Lua image wrapper
48 * -----------------------------
51 #define ROCKLUA_IMAGE "rb.image"
52 struct rocklua_image
54 int width;
55 int height;
56 fb_data *data;
57 fb_data dummy[1][1];
60 static void rli_wrap(lua_State *L, fb_data *src, int width, int height)
62 struct rocklua_image *a = (struct rocklua_image *)lua_newuserdata(L, sizeof(struct rocklua_image));
64 luaL_getmetatable(L, ROCKLUA_IMAGE);
65 lua_setmetatable(L, -2);
67 a->width = width;
68 a->height = height;
69 a->data = src;
72 static fb_data* rli_alloc(lua_State *L, int width, int height)
74 size_t nbytes = sizeof(struct rocklua_image) + ((width*height) - 1) * sizeof(fb_data);
75 struct rocklua_image *a = (struct rocklua_image *)lua_newuserdata(L, nbytes);
77 luaL_getmetatable(L, ROCKLUA_IMAGE);
78 lua_setmetatable(L, -2);
80 a->width = width;
81 a->height = height;
82 a->data = &a->dummy[0][0];
84 return a->data;
87 static int rli_new(lua_State *L)
89 int width = luaL_checkint(L, 1);
90 int height = luaL_checkint(L, 2);
92 rli_alloc(L, width, height);
94 return 1;
97 static struct rocklua_image* rli_checktype(lua_State *L, int arg)
99 void *ud = luaL_checkudata(L, arg, ROCKLUA_IMAGE);
100 luaL_argcheck(L, ud != NULL, arg, "'" ROCKLUA_IMAGE "' expected");
101 return (struct rocklua_image*) ud;
104 static int rli_width(lua_State *L)
106 struct rocklua_image *a = rli_checktype(L, 1);
107 lua_pushnumber(L, a->width);
108 return 1;
111 static int rli_height(lua_State *L)
113 struct rocklua_image *a = rli_checktype(L, 1);
114 lua_pushnumber(L, a->height);
115 return 1;
118 static fb_data* rli_element(lua_State *L)
120 struct rocklua_image *a = rli_checktype(L, 1);
121 int x = luaL_checkint(L, 2);
122 int y = luaL_checkint(L, 3);
124 luaL_argcheck(L, 1 <= x && x <= a->width, 2,
125 "index out of range");
126 luaL_argcheck(L, 1 <= y && y <= a->height, 3,
127 "index out of range");
129 /* return element address */
130 return &a->data[a->width * (y - 1) + (x - 1)];
133 static int rli_set(lua_State *L)
135 fb_data newvalue = (fb_data) luaL_checknumber(L, 4);
136 *rli_element(L) = newvalue;
137 return 0;
140 static int rli_get(lua_State *L)
142 lua_pushnumber(L, *rli_element(L));
143 return 1;
146 static int rli_tostring(lua_State *L)
148 struct rocklua_image *a = rli_checktype(L, 1);
149 lua_pushfstring(L, ROCKLUA_IMAGE ": %dx%d", a->width, a->height);
150 return 1;
153 static const struct luaL_reg rli_lib [] =
155 {"__tostring", rli_tostring},
156 {"set", rli_set},
157 {"get", rli_get},
158 {"width", rli_width},
159 {"height", rli_height},
160 {NULL, NULL}
163 static inline void rli_init(lua_State *L)
165 luaL_newmetatable(L, ROCKLUA_IMAGE);
167 lua_pushstring(L, "__index");
168 lua_pushvalue(L, -2); /* pushes the metatable */
169 lua_settable(L, -3); /* metatable.__index = metatable */
171 luaL_register(L, NULL, rli_lib);
175 * -----------------------------
177 * Rockbox wrappers start here!
179 * -----------------------------
182 #define RB_WRAP(M) static int rock_##M(lua_State *L)
184 /* Helper function for opt_viewport */
185 static void check_tablevalue(lua_State *L, const char* key, int tablepos, void* res, bool unsigned_val)
187 lua_getfield(L, tablepos, key); /* Find table[key] */
189 if(!lua_isnoneornil(L, -1))
191 if(unsigned_val)
192 *(unsigned*)res = luaL_checkint(L, -1);
193 else
194 *(int*)res = luaL_checkint(L, -1);
197 lua_pop(L, 1); /* Pop the value off the stack */
200 static struct viewport* opt_viewport(lua_State *L, int narg, struct viewport* alt)
202 if(lua_isnoneornil(L, narg))
203 return alt;
205 int tablepos = lua_gettop(L);
206 struct viewport *vp;
208 lua_getfield(L, tablepos, "vp"); /* get table['vp'] */
209 if(lua_isnoneornil(L, -1))
211 lua_pop(L, 1); /* Pop nil off stack */
213 vp = (struct viewport*) lua_newuserdata(L, sizeof(struct viewport)); /* Allocate memory and push it as udata on the stack */
214 memset(vp, 0, sizeof(struct viewport)); /* Init viewport values to 0 */
215 lua_setfield(L, tablepos, "vp"); /* table['vp'] = vp (pops value off the stack) */
217 else
219 vp = (struct viewport*) lua_touserdata(L, -1); /* Reuse viewport struct */
220 lua_pop(L, 1); /* We don't need the value on stack */
223 luaL_checktype(L, narg, LUA_TTABLE);
225 check_tablevalue(L, "x", tablepos, &vp->x, false);
226 check_tablevalue(L, "y", tablepos, &vp->y, false);
227 check_tablevalue(L, "width", tablepos, &vp->width, false);
228 check_tablevalue(L, "height", tablepos, &vp->height, false);
229 #ifdef HAVE_LCD_BITMAP
230 check_tablevalue(L, "font", tablepos, &vp->font, false);
231 check_tablevalue(L, "drawmode", tablepos, &vp->drawmode, false);
232 #endif
233 #if LCD_DEPTH > 1
234 check_tablevalue(L, "fg_pattern", tablepos, &vp->fg_pattern, true);
235 check_tablevalue(L, "bg_pattern", tablepos, &vp->bg_pattern, true);
236 #ifdef HAVE_LCD_COLOR
237 check_tablevalue(L, "lss_pattern", tablepos, &vp->lss_pattern, true);
238 check_tablevalue(L, "lse_pattern", tablepos, &vp->lse_pattern, true);
239 check_tablevalue(L, "lst_pattern", tablepos, &vp->lst_pattern, true);
240 #endif
241 #endif
243 return vp;
246 RB_WRAP(set_viewport)
248 struct viewport *vp = opt_viewport(L, 1, NULL);
249 int screen = luaL_optint(L, 2, SCREEN_MAIN);
250 rb->screens[screen]->set_viewport(vp);
251 return 0;
254 RB_WRAP(clear_viewport)
256 int screen = luaL_optint(L, 1, SCREEN_MAIN);
257 rb->screens[screen]->clear_viewport();
258 return 0;
261 RB_WRAP(splash)
263 int ticks = luaL_checkint(L, 1);
264 const char *s = luaL_checkstring(L, 2);
265 rb->splash(ticks, s);
266 return 0;
269 RB_WRAP(lcd_update)
271 (void)L;
272 rb->lcd_update();
273 return 0;
276 RB_WRAP(lcd_update_rect)
278 int x = luaL_checkint(L, 1);
279 int y = luaL_checkint(L, 2);
280 int width = luaL_checkint(L, 3);
281 int height = luaL_checkint(L, 4);
282 rb->lcd_update_rect(x, y, width, height);
283 return 0;
286 RB_WRAP(lcd_clear_display)
288 (void)L;
289 rb->lcd_clear_display();
290 return 0;
293 RB_WRAP(lcd_putsxy)
295 int x = luaL_checkint(L, 1);
296 int y = luaL_checkint(L, 2);
297 const char* string = luaL_checkstring(L, 3);
298 rb->lcd_putsxy(x, y, string);
299 return 0;
302 RB_WRAP(lcd_puts)
304 int x = luaL_checkint(L, 1);
305 int y = luaL_checkint(L, 2);
306 const char* string = luaL_checkstring(L, 3);
307 rb->lcd_puts(x, y, string);
308 return 0;
311 RB_WRAP(lcd_puts_scroll)
313 int x = luaL_checkint(L, 1);
314 int y = luaL_checkint(L, 2);
315 const char* string = luaL_checkstring(L, 3);
316 rb->lcd_puts_scroll(x, y, string);
317 return 0;
320 RB_WRAP(lcd_stop_scroll)
322 (void)L;
323 rb->lcd_stop_scroll();
324 return 0;
327 #ifdef HAVE_LCD_BITMAP
328 RB_WRAP(lcd_framebuffer)
330 rli_wrap(L, rb->lcd_framebuffer, LCD_WIDTH, LCD_HEIGHT);
331 return 1;
334 RB_WRAP(lcd_set_drawmode)
336 int drawmode = luaL_checkint(L, 1);
337 rb->lcd_set_drawmode(drawmode);
338 return 0;
341 RB_WRAP(lcd_get_drawmode)
343 int result = rb->lcd_get_drawmode();
344 lua_pushinteger(L, result);
345 return 1;
348 RB_WRAP(lcd_setfont)
350 int font = luaL_checkint(L, 1);
351 rb->lcd_setfont(font);
352 return 0;
355 RB_WRAP(lcd_drawpixel)
357 int x = luaL_checkint(L, 1);
358 int y = luaL_checkint(L, 2);
360 rb->lcd_drawpixel(x, y);
361 return 0;
364 RB_WRAP(lcd_drawline)
366 int x1 = luaL_checkint(L, 1);
367 int y1 = luaL_checkint(L, 2);
368 int x2 = luaL_checkint(L, 3);
369 int y2 = luaL_checkint(L, 4);
371 rb->lcd_drawline(x1, y1, x2, y2);
372 return 0;
375 RB_WRAP(lcd_hline)
377 int x1 = luaL_checkint(L, 1);
378 int x2 = luaL_checkint(L, 2);
379 int y = luaL_checkint(L, 3);
381 rb->lcd_hline(x1, x2, y);
382 return 0;
385 RB_WRAP(lcd_vline)
387 int x = luaL_checkint(L, 1);
388 int y1 = luaL_checkint(L, 2);
389 int y2 = luaL_checkint(L, 3);
391 rb->lcd_vline(x, y1, y2);
392 return 0;
395 RB_WRAP(lcd_drawrect)
397 int x = luaL_checkint(L, 1);
398 int y = luaL_checkint(L, 2);
399 int width = luaL_checkint(L, 3);
400 int height = luaL_checkint(L, 4);
402 rb->lcd_drawrect(x, y, width, height);
403 return 0;
406 RB_WRAP(lcd_fillrect)
408 int x = luaL_checkint(L, 1);
409 int y = luaL_checkint(L, 2);
410 int width = luaL_checkint(L, 3);
411 int height = luaL_checkint(L, 4);
413 rb->lcd_fillrect(x, y, width, height);
414 return 0;
417 RB_WRAP(lcd_mono_bitmap_part)
419 struct rocklua_image *src = rli_checktype(L, 1);
420 int src_x = luaL_checkint(L, 2);
421 int src_y = luaL_checkint(L, 3);
422 int stride = luaL_checkint(L, 4);
423 int x = luaL_checkint(L, 5);
424 int y = luaL_checkint(L, 6);
425 int width = luaL_checkint(L, 7);
426 int height = luaL_checkint(L, 8);
428 rb->lcd_mono_bitmap_part((const unsigned char *)src->data, src_x, src_y, stride, x, y, width, height);
429 return 0;
432 RB_WRAP(lcd_mono_bitmap)
434 struct rocklua_image *src = rli_checktype(L, 1);
435 int x = luaL_checkint(L, 2);
436 int y = luaL_checkint(L, 3);
437 int width = luaL_checkint(L, 4);
438 int height = luaL_checkint(L, 5);
440 rb->lcd_mono_bitmap((const unsigned char *)src->data, x, y, width, height);
441 return 0;
444 #if LCD_DEPTH > 1
445 RB_WRAP(lcd_set_foreground)
447 unsigned foreground = luaL_checkint(L, 1);
448 rb->lcd_set_foreground(foreground);
449 return 0;
452 RB_WRAP(lcd_get_foreground)
454 unsigned result = rb->lcd_get_foreground();
455 lua_pushinteger(L, result);
456 return 1;
459 RB_WRAP(lcd_set_background)
461 unsigned background = luaL_checkint(L, 1);
462 rb->lcd_set_background(background);
463 return 0;
466 RB_WRAP(lcd_get_background)
468 unsigned result = rb->lcd_get_background();
469 lua_pushinteger(L, result);
470 return 1;
473 RB_WRAP(lcd_bitmap_part)
475 struct rocklua_image *src = rli_checktype(L, 1);
476 int src_x = luaL_checkint(L, 2);
477 int src_y = luaL_checkint(L, 3);
478 int stride = luaL_checkint(L, 4);
479 int x = luaL_checkint(L, 5);
480 int y = luaL_checkint(L, 6);
481 int width = luaL_checkint(L, 7);
482 int height = luaL_checkint(L, 8);
484 rb->lcd_bitmap_part(src->data, src_x, src_y, stride, x, y, width, height);
485 return 0;
488 RB_WRAP(lcd_bitmap)
490 struct rocklua_image *src = rli_checktype(L, 1);
491 int x = luaL_checkint(L, 2);
492 int y = luaL_checkint(L, 3);
493 int width = luaL_checkint(L, 4);
494 int height = luaL_checkint(L, 5);
496 rb->lcd_bitmap(src->data, x, y, width, height);
497 return 0;
500 RB_WRAP(lcd_get_backdrop)
502 fb_data* backdrop = rb->lcd_get_backdrop();
503 if(backdrop == NULL)
504 return 0;
505 else
507 rli_wrap(L, backdrop, LCD_WIDTH, LCD_HEIGHT);
508 return 1;
511 #endif /* LCD_DEPTH > 1 */
513 #if LCD_DEPTH == 16
514 RB_WRAP(lcd_bitmap_transparent_part)
516 struct rocklua_image *src = rli_checktype(L, 1);
517 int src_x = luaL_checkint(L, 2);
518 int src_y = luaL_checkint(L, 3);
519 int stride = luaL_checkint(L, 4);
520 int x = luaL_checkint(L, 5);
521 int y = luaL_checkint(L, 6);
522 int width = luaL_checkint(L, 7);
523 int height = luaL_checkint(L, 8);
525 rb->lcd_bitmap_transparent_part(src->data, src_x, src_y, stride, x, y, width, height);
526 return 0;
529 RB_WRAP(lcd_bitmap_transparent)
531 struct rocklua_image *src = rli_checktype(L, 1);
532 int x = luaL_checkint(L, 2);
533 int y = luaL_checkint(L, 3);
534 int width = luaL_checkint(L, 4);
535 int height = luaL_checkint(L, 5);
537 rb->lcd_bitmap_transparent(src->data, x, y, width, height);
538 return 0;
540 #endif /* LCD_DEPTH == 16 */
542 #endif /* defined(LCD_BITMAP) */
544 RB_WRAP(yield)
546 (void)L;
547 rb->yield();
548 return 0;
551 RB_WRAP(sleep)
553 int ticks = luaL_checkint(L, 1);
554 rb->sleep(ticks);
555 return 0;
558 RB_WRAP(current_tick)
560 lua_pushinteger(L, *rb->current_tick);
561 return 1;
564 RB_WRAP(button_get)
566 bool block = luaL_checkboolean(L, 1);
567 long result = rb->button_get(block);
568 lua_pushinteger(L, result);
569 return 1;
572 RB_WRAP(button_get_w_tmo)
574 int ticks = luaL_checkint(L, 1);
575 long result = rb->button_get_w_tmo(ticks);
576 lua_pushinteger(L, result);
577 return 1;
580 RB_WRAP(button_status)
582 int result = rb->button_status();
583 lua_pushinteger(L, result);
584 return 1;
587 #ifdef HAVE_BUTTON_DATA
588 RB_WRAP(button_get_data)
590 int result = rb->button_get_data();
591 lua_pushinteger(L, result);
592 return 1;
594 #endif
596 #ifdef HAS_BUTTON_HOLD
597 RB_WRAP(button_hold)
599 bool result = rb->button_hold();
600 lua_pushboolean(L, result);
601 return 1;
603 #endif
605 RB_WRAP(get_action)
607 int context = luaL_checkint(L, 1);
608 int timeout = luaL_checkint(L, 2);
609 int result = rb->get_action(context, timeout);
610 lua_pushinteger(L, result);
611 return 1;
614 #ifdef HAVE_TOUCHSCREEN
615 RB_WRAP(action_get_touchscreen_press)
617 short x, y;
618 int result = rb->action_get_touchscreen_press(&x, &y);
620 lua_pushinteger(L, result);
621 lua_pushinteger(L, x);
622 lua_pushinteger(L, y);
623 return 3;
625 #endif
627 RB_WRAP(action_userabort)
629 int timeout = luaL_checkint(L, 1);
630 bool result = rb->action_userabort(timeout);
631 lua_pushboolean(L, result);
632 return 1;
635 RB_WRAP(kbd_input)
637 luaL_Buffer b;
638 luaL_buffinit(L, &b);
640 char *buffer = luaL_prepbuffer(&b);
641 buffer[0] = '\0';
642 rb->kbd_input(buffer, LUAL_BUFFERSIZE);
643 luaL_addsize(&b, strlen(buffer));
645 luaL_pushresult(&b);
646 return 1;
649 #ifdef HAVE_TOUCHSCREEN
650 RB_WRAP(touchscreen_set_mode)
652 enum touchscreen_mode mode = luaL_checkint(L, 1);
653 rb->touchscreen_set_mode(mode);
654 return 0;
656 #endif
658 RB_WRAP(backlight_on)
660 (void)L;
661 rb->backlight_on();
662 return 0;
665 RB_WRAP(backlight_off)
667 (void)L;
668 rb->backlight_off();
669 return 0;
672 RB_WRAP(backlight_set_timeout)
674 int val = luaL_checkint(L, 1);
675 rb->backlight_set_timeout(val);
676 return 0;
679 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
680 RB_WRAP(backlight_set_brightness)
682 int val = luaL_checkint(L, 1);
683 rb->backlight_set_brightness(val);
684 return 0;
686 #endif
688 RB_WRAP(creat)
690 const char* pathname = luaL_checkstring(L, 1);
691 int result = rb->creat(pathname);
692 lua_pushinteger(L, result);
693 return 1;
696 RB_WRAP(remove)
698 const char* pathname = luaL_checkstring(L, 1);
699 int result = rb->remove(pathname);
700 lua_pushinteger(L, result);
701 return 1;
704 RB_WRAP(rename)
706 const char* path = luaL_checkstring(L, 1);
707 const char* newname = luaL_checkstring(L, 2);
708 int result = rb->rename(path, newname);
709 lua_pushinteger(L, result);
710 return 1;
713 RB_WRAP(file_exists)
715 const char* path = luaL_checkstring(L, 1);
716 bool result = rb->file_exists(path);
717 lua_pushboolean(L, result);
718 return 1;
721 RB_WRAP(font_getstringsize)
723 const unsigned char* str = luaL_checkstring(L, 1);
724 int fontnumber = luaL_checkint(L, 2);
725 int w, h;
727 int result = rb->font_getstringsize(str, &w, &h, fontnumber);
728 lua_pushinteger(L, result);
729 lua_pushinteger(L, w);
730 lua_pushinteger(L, h);
732 return 3;
735 #ifdef HAVE_LCD_COLOR
736 RB_WRAP(lcd_rgbpack)
738 int r = luaL_checkint(L, 1);
739 int g = luaL_checkint(L, 2);
740 int b = luaL_checkint(L, 3);
741 int result = LCD_RGBPACK(r, g, b);
742 lua_pushinteger(L, result);
743 return 1;
746 RB_WRAP(lcd_rgbunpack)
748 int rgb = luaL_checkint(L, 1);
749 lua_pushinteger(L, RGB_UNPACK_RED(rgb));
750 lua_pushinteger(L, RGB_UNPACK_GREEN(rgb));
751 lua_pushinteger(L, RGB_UNPACK_BLUE(rgb));
752 return 3;
754 #endif
756 RB_WRAP(read_bmp_file)
758 struct bitmap bm;
759 const char* filename = luaL_checkstring(L, 1);
760 bool dither = luaL_optboolean(L, 2, true);
761 bool transparent = luaL_optboolean(L, 3, false);
762 int format = FORMAT_NATIVE;
764 if(dither)
765 format |= FORMAT_DITHER;
767 if(transparent)
768 format |= FORMAT_TRANSPARENT;
770 int result = rb->read_bmp_file(filename, &bm, 0, format | FORMAT_RETURN_SIZE, NULL);
772 if(result > 0)
774 bm.data = (unsigned char*) rli_alloc(L, bm.width, bm.height);
775 rb->read_bmp_file(filename, &bm, result, format, NULL);
777 return 1;
780 return 0;
783 RB_WRAP(current_path)
785 char buffer[MAX_PATH];
786 lua_Debug ar;
788 if(lua_getstack(L, 1, &ar))
790 /* Try determining the base path of the current Lua chunk
791 and write it to dest. */
792 lua_getinfo(L, "S", &ar);
794 char* curfile = (char*) &ar.source[1];
795 char* pos = rb->strrchr(curfile, '/');
796 if(pos != NULL)
798 unsigned int len = (unsigned int)(pos - curfile);
799 len = len + 1 > sizeof(buffer) ? sizeof(buffer) - 1 : len;
801 if(len > 0)
802 memcpy(buffer, curfile, len);
804 buffer[len] = '/';
805 buffer[len+1] = '\0';
807 lua_pushstring(L, buffer);
808 return 1;
812 return 0;
815 #define R(NAME) {#NAME, rock_##NAME}
816 static const luaL_Reg rocklib[] =
818 /* Graphics */
819 R(lcd_clear_display),
820 R(lcd_update),
821 R(lcd_update_rect),
822 R(lcd_puts),
823 R(lcd_putsxy),
824 R(lcd_puts_scroll),
825 R(lcd_stop_scroll),
826 R(splash),
827 #ifdef HAVE_LCD_BITMAP
828 R(lcd_framebuffer),
829 R(lcd_set_drawmode),
830 R(lcd_get_drawmode),
831 R(lcd_setfont),
832 R(lcd_drawline),
833 R(lcd_drawpixel),
834 R(lcd_hline),
835 R(lcd_vline),
836 R(lcd_drawrect),
837 R(lcd_fillrect),
838 R(lcd_mono_bitmap_part),
839 R(lcd_mono_bitmap),
840 #if LCD_DEPTH > 1
841 R(lcd_set_foreground),
842 R(lcd_get_foreground),
843 R(lcd_set_background),
844 R(lcd_get_background),
845 R(lcd_get_backdrop),
846 R(lcd_bitmap_part),
847 R(lcd_bitmap),
848 #endif
849 #if LCD_DEPTH == 16
850 R(lcd_bitmap_transparent_part),
851 R(lcd_bitmap_transparent),
852 #endif
853 #endif
854 #ifdef HAVE_LCD_COLOR
855 R(lcd_rgbpack),
856 R(lcd_rgbunpack),
857 #endif
859 /* File handling */
860 R(creat),
861 R(remove),
862 R(rename),
863 R(file_exists),
865 /* Kernel */
866 R(sleep),
867 R(yield),
868 R(current_tick),
870 /* Buttons */
871 R(button_get),
872 R(button_get_w_tmo),
873 R(button_status),
874 #ifdef HAVE_BUTTON_DATA
875 R(button_get_data),
876 #endif
877 #ifdef HAS_BUTTON_HOLD
878 R(button_hold),
879 #endif
880 R(get_action),
881 R(action_userabort),
882 #ifdef HAVE_TOUCHSCREEN
883 R(action_get_touchscreen_press),
884 R(touchscreen_set_mode),
885 #endif
886 R(kbd_input),
888 /* Hardware */
889 R(backlight_on),
890 R(backlight_off),
891 R(backlight_set_timeout),
892 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
893 R(backlight_set_brightness),
894 #endif
896 R(font_getstringsize),
897 R(read_bmp_file),
898 R(set_viewport),
899 R(clear_viewport),
900 R(current_path),
902 {"new_image", rli_new},
904 {NULL, NULL}
906 #undef R
908 #define RB_CONSTANT(x) lua_pushinteger(L, x); lua_setfield(L, -2, #x);
910 ** Open Rockbox library
912 LUALIB_API int luaopen_rock(lua_State *L)
914 luaL_register(L, LUA_ROCKLIBNAME, rocklib);
916 RB_CONSTANT(HZ);
918 RB_CONSTANT(LCD_WIDTH);
919 RB_CONSTANT(LCD_HEIGHT);
921 RB_CONSTANT(FONT_SYSFIXED);
922 RB_CONSTANT(FONT_UI);
924 #ifdef HAVE_TOUCHSCREEN
925 RB_CONSTANT(TOUCHSCREEN_POINT);
926 RB_CONSTANT(TOUCHSCREEN_BUTTON);
927 RB_CONSTANT(BUTTON_TOUCHSCREEN);
928 #endif
930 RB_CONSTANT(BUTTON_REL);
931 RB_CONSTANT(BUTTON_REPEAT);
933 rli_init(L);
935 return 1;