summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2009-05-21 19:42:14 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2009-05-21 19:42:14 +0000
commita9b2d1b5fa516cc2ea46147fc51589b6e68a2e5d (patch)
tree1dac659097fc0f75bfa356d1d802910f5995c931
parent7a04a54c52215d2149168d5347c347ab41e91c47 (diff)
downloadrockbox-a9b2d1b5fa516cc2ea46147fc51589b6e68a2e5d.tar.gz
rockbox-a9b2d1b5fa516cc2ea46147fc51589b6e68a2e5d.zip
Lua: fix some issues with rocklib
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21022 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/lua/rocklib.c63
1 files changed, 34 insertions, 29 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 60c51f3206..8eaa13348e 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -28,6 +28,16 @@
28#include "lauxlib.h" 28#include "lauxlib.h"
29#include "rocklib.h" 29#include "rocklib.h"
30 30
31/*
32 * http://www.lua.org/manual/5.1/manual.html#lua_CFunction
33 *
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.
40 */
31#define RB_WRAP(M) static int rock_##M(lua_State *L) 41#define RB_WRAP(M) static int rock_##M(lua_State *L)
32 42
33RB_WRAP(splash) 43RB_WRAP(splash)
@@ -35,21 +45,21 @@ RB_WRAP(splash)
35 int ticks = luaL_checkint(L, 1); 45 int ticks = luaL_checkint(L, 1);
36 const char *s = luaL_checkstring(L, 2); 46 const char *s = luaL_checkstring(L, 2);
37 rb->splash(ticks, s); 47 rb->splash(ticks, s);
38 return 1; 48 return 0;
39} 49}
40 50
41RB_WRAP(lcd_update) 51RB_WRAP(lcd_update)
42{ 52{
43 (void)L; 53 (void)L;
44 rb->lcd_update(); 54 rb->lcd_update();
45 return 1; 55 return 0;
46} 56}
47 57
48RB_WRAP(lcd_clear_display) 58RB_WRAP(lcd_clear_display)
49{ 59{
50 (void)L; 60 (void)L;
51 rb->lcd_clear_display(); 61 rb->lcd_clear_display();
52 return 1; 62 return 0;
53} 63}
54 64
55RB_WRAP(lcd_putsxy) 65RB_WRAP(lcd_putsxy)
@@ -58,7 +68,7 @@ RB_WRAP(lcd_putsxy)
58 int y = luaL_checkint(L, 2); 68 int y = luaL_checkint(L, 2);
59 const char* string = luaL_checkstring(L, 3); 69 const char* string = luaL_checkstring(L, 3);
60 rb->lcd_putsxy(x, y, string); 70 rb->lcd_putsxy(x, y, string);
61 return 1; 71 return 0;
62} 72}
63 73
64RB_WRAP(lcd_puts) 74RB_WRAP(lcd_puts)
@@ -67,7 +77,7 @@ RB_WRAP(lcd_puts)
67 int y = luaL_checkint(L, 2); 77 int y = luaL_checkint(L, 2);
68 const char* string = luaL_checkstring(L, 3); 78 const char* string = luaL_checkstring(L, 3);
69 rb->lcd_puts(x, y, string); 79 rb->lcd_puts(x, y, string);
70 return 1; 80 return 0;
71} 81}
72 82
73RB_WRAP(lcd_puts_scroll) 83RB_WRAP(lcd_puts_scroll)
@@ -76,14 +86,14 @@ RB_WRAP(lcd_puts_scroll)
76 int y = luaL_checkint(L, 2); 86 int y = luaL_checkint(L, 2);
77 const char* string = luaL_checkstring(L, 3); 87 const char* string = luaL_checkstring(L, 3);
78 rb->lcd_puts_scroll(x, y, string); 88 rb->lcd_puts_scroll(x, y, string);
79 return 1; 89 return 0;
80} 90}
81 91
82RB_WRAP(lcd_stop_scroll) 92RB_WRAP(lcd_stop_scroll)
83{ 93{
84 (void)L; 94 (void)L;
85 rb->lcd_stop_scroll(); 95 rb->lcd_stop_scroll();
86 return 1; 96 return 0;
87} 97}
88 98
89#ifdef HAVE_LCD_BITMAP 99#ifdef HAVE_LCD_BITMAP
@@ -91,7 +101,7 @@ RB_WRAP(lcd_set_drawmode)
91{ 101{
92 int drawmode = luaL_checkint(L, 1); 102 int drawmode = luaL_checkint(L, 1);
93 rb->lcd_set_drawmode(drawmode); 103 rb->lcd_set_drawmode(drawmode);
94 return 1; 104 return 0;
95} 105}
96 106
97RB_WRAP(lcd_get_drawmode) 107RB_WRAP(lcd_get_drawmode)
@@ -105,7 +115,7 @@ RB_WRAP(lcd_setfont)
105{ 115{
106 int font = luaL_checkint(L, 1); 116 int font = luaL_checkint(L, 1);
107 rb->lcd_setfont(font); 117 rb->lcd_setfont(font);
108 return 1; 118 return 0;
109} 119}
110 120
111RB_WRAP(lcd_drawpixel) 121RB_WRAP(lcd_drawpixel)
@@ -114,8 +124,7 @@ RB_WRAP(lcd_drawpixel)
114 int y = luaL_checkint(L, 2); 124 int y = luaL_checkint(L, 2);
115 125
116 rb->lcd_drawpixel(x, y); 126 rb->lcd_drawpixel(x, y);
117 127 return 0;
118 return 1;
119} 128}
120 129
121RB_WRAP(lcd_drawline) 130RB_WRAP(lcd_drawline)
@@ -126,8 +135,7 @@ RB_WRAP(lcd_drawline)
126 int y2 = luaL_checkint(L, 4); 135 int y2 = luaL_checkint(L, 4);
127 136
128 rb->lcd_drawline(x1, y1, x2, y2); 137 rb->lcd_drawline(x1, y1, x2, y2);
129 138 return 0;
130 return 1;
131} 139}
132 140
133RB_WRAP(lcd_hline) 141RB_WRAP(lcd_hline)
@@ -137,8 +145,7 @@ RB_WRAP(lcd_hline)
137 int y = luaL_checkint(L, 3); 145 int y = luaL_checkint(L, 3);
138 146
139 rb->lcd_hline(x1, x2, y); 147 rb->lcd_hline(x1, x2, y);
140 148 return 0;
141 return 1;
142} 149}
143 150
144RB_WRAP(lcd_vline) 151RB_WRAP(lcd_vline)
@@ -148,8 +155,7 @@ RB_WRAP(lcd_vline)
148 int y2 = luaL_checkint(L, 3); 155 int y2 = luaL_checkint(L, 3);
149 156
150 rb->lcd_vline(x, y1, y2); 157 rb->lcd_vline(x, y1, y2);
151 158 return 0;
152 return 1;
153} 159}
154 160
155RB_WRAP(lcd_drawrect) 161RB_WRAP(lcd_drawrect)
@@ -160,8 +166,7 @@ RB_WRAP(lcd_drawrect)
160 int height = luaL_checkint(L, 4); 166 int height = luaL_checkint(L, 4);
161 167
162 rb->lcd_drawrect(x, y, width, height); 168 rb->lcd_drawrect(x, y, width, height);
163 169 return 0;
164 return 1;
165} 170}
166 171
167RB_WRAP(lcd_fillrect) 172RB_WRAP(lcd_fillrect)
@@ -172,8 +177,7 @@ RB_WRAP(lcd_fillrect)
172 int height = luaL_checkint(L, 4); 177 int height = luaL_checkint(L, 4);
173 178
174 rb->lcd_fillrect(x, y, width, height); 179 rb->lcd_fillrect(x, y, width, height);
175 180 return 0;
176 return 1;
177} 181}
178#endif 182#endif
179 183
@@ -181,14 +185,14 @@ RB_WRAP(yield)
181{ 185{
182 (void)L; 186 (void)L;
183 rb->yield(); 187 rb->yield();
184 return 1; 188 return 0;
185} 189}
186 190
187RB_WRAP(sleep) 191RB_WRAP(sleep)
188{ 192{
189 int ticks = luaL_checkint(L, 1); 193 int ticks = luaL_checkint(L, 1);
190 rb->sleep(ticks); 194 rb->sleep(ticks);
191 return 1; 195 return 0;
192} 196}
193 197
194RB_WRAP(current_tick) 198RB_WRAP(current_tick)
@@ -268,21 +272,21 @@ RB_WRAP(backlight_on)
268{ 272{
269 (void)L; 273 (void)L;
270 rb->backlight_on(); 274 rb->backlight_on();
271 return 1; 275 return 0;
272} 276}
273 277
274RB_WRAP(backlight_off) 278RB_WRAP(backlight_off)
275{ 279{
276 (void)L; 280 (void)L;
277 rb->backlight_off(); 281 rb->backlight_off();
278 return 1; 282 return 0;
279} 283}
280 284
281RB_WRAP(backlight_set_timeout) 285RB_WRAP(backlight_set_timeout)
282{ 286{
283 int val = luaL_checkint(L, 1); 287 int val = luaL_checkint(L, 1);
284 rb->backlight_set_timeout(val); 288 rb->backlight_set_timeout(val);
285 return 1; 289 return 0;
286} 290}
287 291
288#ifdef HAVE_BACKLIGHT_BRIGHTNESS 292#ifdef HAVE_BACKLIGHT_BRIGHTNESS
@@ -290,13 +294,13 @@ RB_WRAP(backlight_set_brightness)
290{ 294{
291 int val = luaL_checkint(L, 1); 295 int val = luaL_checkint(L, 1);
292 rb->backlight_set_brightness(val); 296 rb->backlight_set_brightness(val);
293 return 1; 297 return 0;
294} 298}
295#endif 299#endif
296 300
297
298#define R(NAME) {#NAME, rock_##NAME} 301#define R(NAME) {#NAME, rock_##NAME}
299static const luaL_Reg rocklib[] = { 302static const luaL_Reg rocklib[] =
303{
300 /* Graphics */ 304 /* Graphics */
301 R(lcd_clear_display), 305 R(lcd_clear_display),
302 R(lcd_update), 306 R(lcd_update),
@@ -355,6 +359,7 @@ static const luaL_Reg rocklib[] = {
355LUALIB_API int luaopen_rock(lua_State *L) 359LUALIB_API int luaopen_rock(lua_State *L)
356{ 360{
357 luaL_register(L, LUA_ROCKLIBNAME, rocklib); 361 luaL_register(L, LUA_ROCKLIBNAME, rocklib);
362
358 RB_CONSTANT(HZ); 363 RB_CONSTANT(HZ);
359 RB_CONSTANT(LCD_WIDTH); 364 RB_CONSTANT(LCD_WIDTH);
360 RB_CONSTANT(LCD_HEIGHT); 365 RB_CONSTANT(LCD_HEIGHT);