summaryrefslogtreecommitdiff
path: root/apps/plugins/lua
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua')
-rw-r--r--apps/plugins/lua/lauxlib.c13
-rw-r--r--apps/plugins/lua/lauxlib.h4
-rw-r--r--apps/plugins/lua/rocklib.c47
3 files changed, 59 insertions, 5 deletions
diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c
index 88abc3cde0..fd71e07217 100644
--- a/apps/plugins/lua/lauxlib.c
+++ b/apps/plugins/lua/lauxlib.c
@@ -200,6 +200,19 @@ LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
200} 200}
201 201
202 202
203LUALIB_API int luaL_checkboolean (lua_State *L, int narg) {
204 int b = lua_toboolean(L, narg);
205 if( b == 0 && !lua_isboolean(L, narg))
206 tag_error(L, narg, LUA_TBOOLEAN);
207 return b;
208}
209
210
211LUALIB_API int luaL_optboolean (lua_State *L, int narg, int def) {
212 return luaL_opt(L, luaL_checkboolean, narg, def);
213}
214
215
203LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { 216LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
204 if (!lua_getmetatable(L, obj)) /* no metatable? */ 217 if (!lua_getmetatable(L, obj)) /* no metatable? */
205 return 0; 218 return 0;
diff --git a/apps/plugins/lua/lauxlib.h b/apps/plugins/lua/lauxlib.h
index d58f290527..a36de351fe 100644
--- a/apps/plugins/lua/lauxlib.h
+++ b/apps/plugins/lua/lauxlib.h
@@ -58,6 +58,10 @@ LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
58LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, 58LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
59 lua_Integer def); 59 lua_Integer def);
60 60
61LUALIB_API int (luaL_checkboolean) (lua_State *L, int numArg);
62LUALIB_API int (luaL_optboolean) (lua_State *L, int nArg,
63 int def);
64
61LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 65LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
62LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); 66LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
63LUALIB_API void (luaL_checkany) (lua_State *L, int narg); 67LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 692106e24d..4dc7081711 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -69,11 +69,9 @@ static void rli_wrap(lua_State *L, fb_data *src, int width, int height)
69 a->data = src; 69 a->data = src;
70} 70}
71 71
72static int rli_new(lua_State *L) 72static fb_data* rli_alloc(lua_State *L, int width, int height)
73{ 73{
74 int width = luaL_checkint(L, 1); 74 size_t nbytes = sizeof(struct rocklua_image) + ((width*height) - 1) * sizeof(fb_data);
75 int height = luaL_checkint(L, 2);
76 size_t nbytes = sizeof(struct rocklua_image) + (width - 1)*(height - 1)*sizeof(fb_data);
77 struct rocklua_image *a = (struct rocklua_image *)lua_newuserdata(L, nbytes); 75 struct rocklua_image *a = (struct rocklua_image *)lua_newuserdata(L, nbytes);
78 76
79 luaL_getmetatable(L, ROCKLUA_IMAGE); 77 luaL_getmetatable(L, ROCKLUA_IMAGE);
@@ -82,6 +80,17 @@ static int rli_new(lua_State *L)
82 a->width = width; 80 a->width = width;
83 a->height = height; 81 a->height = height;
84 a->data = &a->dummy[0][0]; 82 a->data = &a->dummy[0][0];
83
84 return a->data;
85}
86
87static int rli_new(lua_State *L)
88{
89 int width = luaL_checkint(L, 1);
90 int height = luaL_checkint(L, 2);
91
92 rli_alloc(L, width, height);
93
85 return 1; 94 return 1;
86} 95}
87 96
@@ -450,7 +459,7 @@ RB_WRAP(current_tick)
450 459
451RB_WRAP(button_get) 460RB_WRAP(button_get)
452{ 461{
453 bool block = lua_toboolean(L, 1); 462 bool block = luaL_checkboolean(L, 1);
454 long result = rb->button_get(block); 463 long result = rb->button_get(block);
455 lua_pushinteger(L, result); 464 lua_pushinteger(L, result);
456 return 1; 465 return 1;
@@ -714,6 +723,33 @@ RB_WRAP(lcd_rgbunpack)
714} 723}
715#endif 724#endif
716 725
726RB_WRAP(read_bmp_file)
727{
728 struct bitmap bm;
729 const char* filename = luaL_checkstring(L, 1);
730 bool dither = luaL_optboolean(L, 2, true);
731 bool transparent = luaL_optboolean(L, 3, false);
732 int format = FORMAT_NATIVE;
733
734 if(dither)
735 format |= FORMAT_DITHER;
736
737 if(transparent)
738 format |= FORMAT_TRANSPARENT;
739
740 int result = rb->read_bmp_file(filename, &bm, 0, format | FORMAT_RETURN_SIZE, NULL);
741
742 if(result > 0)
743 {
744 bm.data = (unsigned char*) rli_alloc(L, bm.width, bm.height);
745 rb->read_bmp_file(filename, &bm, result, format, NULL);
746
747 return 1;
748 }
749
750 return 0;
751}
752
717#define R(NAME) {#NAME, rock_##NAME} 753#define R(NAME) {#NAME, rock_##NAME}
718static const luaL_Reg rocklib[] = 754static const luaL_Reg rocklib[] =
719{ 755{
@@ -800,6 +836,7 @@ static const luaL_Reg rocklib[] =
800#endif 836#endif
801 837
802 R(font_getstringsize), 838 R(font_getstringsize),
839 R(read_bmp_file),
803 840
804 {"new_image", rli_new}, 841 {"new_image", rli_new},
805 842