diff options
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r-- | apps/plugins/lua/rocklib.c | 364 |
1 files changed, 364 insertions, 0 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c new file mode 100644 index 0000000000..60c51f3206 --- /dev/null +++ b/apps/plugins/lua/rocklib.c | |||
@@ -0,0 +1,364 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 Dan Everton (safetydan) | ||
11 | * Copyright (C) 2009 Maurus Cuelenaere | ||
12 | * | ||
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. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | |||
23 | #define lrocklib_c | ||
24 | #define LUA_LIB | ||
25 | |||
26 | #include "lua.h" | ||
27 | |||
28 | #include "lauxlib.h" | ||
29 | #include "rocklib.h" | ||
30 | |||
31 | #define RB_WRAP(M) static int rock_##M(lua_State *L) | ||
32 | |||
33 | RB_WRAP(splash) | ||
34 | { | ||
35 | int ticks = luaL_checkint(L, 1); | ||
36 | const char *s = luaL_checkstring(L, 2); | ||
37 | rb->splash(ticks, s); | ||
38 | return 1; | ||
39 | } | ||
40 | |||
41 | RB_WRAP(lcd_update) | ||
42 | { | ||
43 | (void)L; | ||
44 | rb->lcd_update(); | ||
45 | return 1; | ||
46 | } | ||
47 | |||
48 | RB_WRAP(lcd_clear_display) | ||
49 | { | ||
50 | (void)L; | ||
51 | rb->lcd_clear_display(); | ||
52 | return 1; | ||
53 | } | ||
54 | |||
55 | RB_WRAP(lcd_putsxy) | ||
56 | { | ||
57 | int x = luaL_checkint(L, 1); | ||
58 | int y = luaL_checkint(L, 2); | ||
59 | const char* string = luaL_checkstring(L, 3); | ||
60 | rb->lcd_putsxy(x, y, string); | ||
61 | return 1; | ||
62 | } | ||
63 | |||
64 | RB_WRAP(lcd_puts) | ||
65 | { | ||
66 | int x = luaL_checkint(L, 1); | ||
67 | int y = luaL_checkint(L, 2); | ||
68 | const char* string = luaL_checkstring(L, 3); | ||
69 | rb->lcd_puts(x, y, string); | ||
70 | return 1; | ||
71 | } | ||
72 | |||
73 | RB_WRAP(lcd_puts_scroll) | ||
74 | { | ||
75 | int x = luaL_checkint(L, 1); | ||
76 | int y = luaL_checkint(L, 2); | ||
77 | const char* string = luaL_checkstring(L, 3); | ||
78 | rb->lcd_puts_scroll(x, y, string); | ||
79 | return 1; | ||
80 | } | ||
81 | |||
82 | RB_WRAP(lcd_stop_scroll) | ||
83 | { | ||
84 | (void)L; | ||
85 | rb->lcd_stop_scroll(); | ||
86 | return 1; | ||
87 | } | ||
88 | |||
89 | #ifdef HAVE_LCD_BITMAP | ||
90 | RB_WRAP(lcd_set_drawmode) | ||
91 | { | ||
92 | int drawmode = luaL_checkint(L, 1); | ||
93 | rb->lcd_set_drawmode(drawmode); | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | RB_WRAP(lcd_get_drawmode) | ||
98 | { | ||
99 | int result = rb->lcd_get_drawmode(); | ||
100 | lua_pushinteger(L, result); | ||
101 | return 1; | ||
102 | } | ||
103 | |||
104 | RB_WRAP(lcd_setfont) | ||
105 | { | ||
106 | int font = luaL_checkint(L, 1); | ||
107 | rb->lcd_setfont(font); | ||
108 | return 1; | ||
109 | } | ||
110 | |||
111 | RB_WRAP(lcd_drawpixel) | ||
112 | { | ||
113 | int x = luaL_checkint(L, 1); | ||
114 | int y = luaL_checkint(L, 2); | ||
115 | |||
116 | rb->lcd_drawpixel(x, y); | ||
117 | |||
118 | return 1; | ||
119 | } | ||
120 | |||
121 | RB_WRAP(lcd_drawline) | ||
122 | { | ||
123 | int x1 = luaL_checkint(L, 1); | ||
124 | int y1 = luaL_checkint(L, 2); | ||
125 | int x2 = luaL_checkint(L, 3); | ||
126 | int y2 = luaL_checkint(L, 4); | ||
127 | |||
128 | rb->lcd_drawline(x1, y1, x2, y2); | ||
129 | |||
130 | return 1; | ||
131 | } | ||
132 | |||
133 | RB_WRAP(lcd_hline) | ||
134 | { | ||
135 | int x1 = luaL_checkint(L, 1); | ||
136 | int x2 = luaL_checkint(L, 2); | ||
137 | int y = luaL_checkint(L, 3); | ||
138 | |||
139 | rb->lcd_hline(x1, x2, y); | ||
140 | |||
141 | return 1; | ||
142 | } | ||
143 | |||
144 | RB_WRAP(lcd_vline) | ||
145 | { | ||
146 | int x = luaL_checkint(L, 1); | ||
147 | int y1 = luaL_checkint(L, 2); | ||
148 | int y2 = luaL_checkint(L, 3); | ||
149 | |||
150 | rb->lcd_vline(x, y1, y2); | ||
151 | |||
152 | return 1; | ||
153 | } | ||
154 | |||
155 | RB_WRAP(lcd_drawrect) | ||
156 | { | ||
157 | int x = luaL_checkint(L, 1); | ||
158 | int y = luaL_checkint(L, 2); | ||
159 | int width = luaL_checkint(L, 3); | ||
160 | int height = luaL_checkint(L, 4); | ||
161 | |||
162 | rb->lcd_drawrect(x, y, width, height); | ||
163 | |||
164 | return 1; | ||
165 | } | ||
166 | |||
167 | RB_WRAP(lcd_fillrect) | ||
168 | { | ||
169 | int x = luaL_checkint(L, 1); | ||
170 | int y = luaL_checkint(L, 2); | ||
171 | int width = luaL_checkint(L, 3); | ||
172 | int height = luaL_checkint(L, 4); | ||
173 | |||
174 | rb->lcd_fillrect(x, y, width, height); | ||
175 | |||
176 | return 1; | ||
177 | } | ||
178 | #endif | ||
179 | |||
180 | RB_WRAP(yield) | ||
181 | { | ||
182 | (void)L; | ||
183 | rb->yield(); | ||
184 | return 1; | ||
185 | } | ||
186 | |||
187 | RB_WRAP(sleep) | ||
188 | { | ||
189 | int ticks = luaL_checkint(L, 1); | ||
190 | rb->sleep(ticks); | ||
191 | return 1; | ||
192 | } | ||
193 | |||
194 | RB_WRAP(current_tick) | ||
195 | { | ||
196 | lua_pushinteger(L, *rb->current_tick); | ||
197 | return 1; | ||
198 | } | ||
199 | |||
200 | RB_WRAP(button_get) | ||
201 | { | ||
202 | bool block = lua_toboolean(L, 1); | ||
203 | long result = rb->button_get(block); | ||
204 | lua_pushinteger(L, result); | ||
205 | return 1; | ||
206 | } | ||
207 | |||
208 | RB_WRAP(button_get_w_tmo) | ||
209 | { | ||
210 | int ticks = luaL_checkint(L, 1); | ||
211 | long result = rb->button_get_w_tmo(ticks); | ||
212 | lua_pushinteger(L, result); | ||
213 | return 1; | ||
214 | } | ||
215 | |||
216 | RB_WRAP(button_status) | ||
217 | { | ||
218 | int result = rb->button_status(); | ||
219 | lua_pushinteger(L, result); | ||
220 | return 1; | ||
221 | } | ||
222 | |||
223 | #ifdef HAVE_BUTTON_DATA | ||
224 | RB_WRAP(button_get_data) | ||
225 | { | ||
226 | int result = rb->button_get_data(); | ||
227 | lua_pushinteger(L, result); | ||
228 | return 1; | ||
229 | } | ||
230 | #endif | ||
231 | |||
232 | #ifdef HAS_BUTTON_HOLD | ||
233 | RB_WRAP(button_hold) | ||
234 | { | ||
235 | bool result = rb->button_hold(); | ||
236 | lua_pushboolean(L, result); | ||
237 | return 1; | ||
238 | } | ||
239 | #endif | ||
240 | |||
241 | RB_WRAP(get_action) | ||
242 | { | ||
243 | int context = luaL_checkint(L, 1); | ||
244 | int timeout = luaL_checkint(L, 2); | ||
245 | int result = rb->get_action(context, timeout); | ||
246 | lua_pushinteger(L, result); | ||
247 | return 1; | ||
248 | } | ||
249 | |||
250 | RB_WRAP(action_userabort) | ||
251 | { | ||
252 | int timeout = luaL_checkint(L, 1); | ||
253 | bool result = rb->action_userabort(timeout); | ||
254 | lua_pushboolean(L, result); | ||
255 | return 1; | ||
256 | } | ||
257 | |||
258 | RB_WRAP(kbd_input) | ||
259 | { | ||
260 | char* buffer = (char*)luaL_checkstring(L, 1); | ||
261 | int buflen = luaL_checkint(L, 2); | ||
262 | int result = rb->kbd_input(buffer, buflen); | ||
263 | lua_pushinteger(L, result); | ||
264 | return 1; | ||
265 | } | ||
266 | |||
267 | RB_WRAP(backlight_on) | ||
268 | { | ||
269 | (void)L; | ||
270 | rb->backlight_on(); | ||
271 | return 1; | ||
272 | } | ||
273 | |||
274 | RB_WRAP(backlight_off) | ||
275 | { | ||
276 | (void)L; | ||
277 | rb->backlight_off(); | ||
278 | return 1; | ||
279 | } | ||
280 | |||
281 | RB_WRAP(backlight_set_timeout) | ||
282 | { | ||
283 | int val = luaL_checkint(L, 1); | ||
284 | rb->backlight_set_timeout(val); | ||
285 | return 1; | ||
286 | } | ||
287 | |||
288 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS | ||
289 | RB_WRAP(backlight_set_brightness) | ||
290 | { | ||
291 | int val = luaL_checkint(L, 1); | ||
292 | rb->backlight_set_brightness(val); | ||
293 | return 1; | ||
294 | } | ||
295 | #endif | ||
296 | |||
297 | |||
298 | #define R(NAME) {#NAME, rock_##NAME} | ||
299 | static const luaL_Reg rocklib[] = { | ||
300 | /* Graphics */ | ||
301 | R(lcd_clear_display), | ||
302 | R(lcd_update), | ||
303 | R(lcd_puts), | ||
304 | R(lcd_putsxy), | ||
305 | R(lcd_puts_scroll), | ||
306 | R(lcd_stop_scroll), | ||
307 | R(splash), | ||
308 | #ifdef HAVE_LCD_BITMAP | ||
309 | R(lcd_set_drawmode), | ||
310 | R(lcd_get_drawmode), | ||
311 | R(lcd_setfont), | ||
312 | R(lcd_drawline), | ||
313 | R(lcd_drawpixel), | ||
314 | R(lcd_hline), | ||
315 | R(lcd_vline), | ||
316 | R(lcd_drawrect), | ||
317 | R(lcd_fillrect), | ||
318 | #endif | ||
319 | |||
320 | /* Kernel */ | ||
321 | R(sleep), | ||
322 | R(yield), | ||
323 | R(current_tick), | ||
324 | |||
325 | /* Buttons */ | ||
326 | R(button_get), | ||
327 | R(button_get_w_tmo), | ||
328 | R(button_status), | ||
329 | #ifdef HAVE_BUTTON_DATA | ||
330 | R(button_get_data), | ||
331 | #endif | ||
332 | #ifdef HAS_BUTTON_HOLD | ||
333 | R(button_hold), | ||
334 | #endif | ||
335 | R(get_action), | ||
336 | R(action_userabort), | ||
337 | R(kbd_input), | ||
338 | |||
339 | /* Hardware */ | ||
340 | R(backlight_on), | ||
341 | R(backlight_off), | ||
342 | R(backlight_set_timeout), | ||
343 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS | ||
344 | R(backlight_set_brightness), | ||
345 | #endif | ||
346 | |||
347 | {NULL, NULL} | ||
348 | }; | ||
349 | #undef R | ||
350 | |||
351 | #define RB_CONSTANT(x) lua_pushinteger(L, x); lua_setfield(L, -2, #x); | ||
352 | /* | ||
353 | ** Open Rockbox library | ||
354 | */ | ||
355 | LUALIB_API int luaopen_rock(lua_State *L) | ||
356 | { | ||
357 | luaL_register(L, LUA_ROCKLIBNAME, rocklib); | ||
358 | RB_CONSTANT(HZ); | ||
359 | RB_CONSTANT(LCD_WIDTH); | ||
360 | RB_CONSTANT(LCD_HEIGHT); | ||
361 | |||
362 | return 1; | ||
363 | } | ||
364 | |||