summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rocklib.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r--apps/plugins/lua/rocklib.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 27c1177748..f214aca694 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -156,7 +156,19 @@ static int rli_tostring(lua_State *L)
156 return 1; 156 return 1;
157} 157}
158 158
159static const struct luaL_reg rli_lib [] = 159int rli_checkboolean (lua_State *L, int narg) {
160 int b = lua_toboolean(L, narg);
161 if (b == 0)
162 luaL_checktype(L, narg, LUA_TBOOLEAN);
163 return b;
164}
165
166
167int rli_optboolean (lua_State *L, int narg, int def) {
168 return luaL_opt(L, rli_checkboolean, narg, def);
169}
170
171static const struct luaL_Reg rli_lib [] =
160{ 172{
161 {"__tostring", rli_tostring}, 173 {"__tostring", rli_tostring},
162 {"set", rli_set}, 174 {"set", rli_set},
@@ -472,8 +484,8 @@ RB_WRAP(read_bmp_file)
472{ 484{
473 struct bitmap bm; 485 struct bitmap bm;
474 const char* filename = luaL_checkstring(L, 1); 486 const char* filename = luaL_checkstring(L, 1);
475 bool dither = luaL_optboolean(L, 2, true); 487 bool dither = rli_optboolean(L, 2, true);
476 bool transparent = luaL_optboolean(L, 3, false); 488 bool transparent = rli_optboolean(L, 3, false);
477 int format = FORMAT_NATIVE; 489 int format = FORMAT_NATIVE;
478 490
479 if(dither) 491 if(dither)
@@ -516,7 +528,7 @@ static void fill_text_message(lua_State *L, struct text_message * message,
516{ 528{
517 int i; 529 int i;
518 luaL_checktype(L, pos, LUA_TTABLE); 530 luaL_checktype(L, pos, LUA_TTABLE);
519 int n = luaL_getn(L, pos); 531 int n = lua_rawlen(L, pos);
520 const char **lines = (const char**) tlsf_malloc(n * sizeof(const char*)); 532 const char **lines = (const char**) tlsf_malloc(n * sizeof(const char*));
521 if(lines == NULL) 533 if(lines == NULL)
522 luaL_error(L, "Can't allocate %d bytes!", n * sizeof(const char*)); 534 luaL_error(L, "Can't allocate %d bytes!", n * sizeof(const char*));
@@ -565,7 +577,7 @@ RB_WRAP(do_menu)
565 luaL_checktype(L, 2, LUA_TTABLE); 577 luaL_checktype(L, 2, LUA_TTABLE);
566 start_selected = luaL_optint(L, 3, 0); 578 start_selected = luaL_optint(L, 3, 0);
567 579
568 n = luaL_getn(L, 2); 580 n = lua_rawlen(L, 2);
569 items = (const char**) tlsf_malloc(n * sizeof(const char*)); 581 items = (const char**) tlsf_malloc(n * sizeof(const char*));
570 if(items == NULL) 582 if(items == NULL)
571 luaL_error(L, "Can't allocate %d bytes!", n * sizeof(const char*)); 583 luaL_error(L, "Can't allocate %d bytes!", n * sizeof(const char*));
@@ -758,8 +770,9 @@ extern const luaL_Reg rocklib_aux[];
758 */ 770 */
759LUALIB_API int luaopen_rock(lua_State *L) 771LUALIB_API int luaopen_rock(lua_State *L)
760{ 772{
761 luaL_register(L, LUA_ROCKLIBNAME, rocklib); 773 rli_init(L);
762 luaL_register(L, LUA_ROCKLIBNAME, rocklib_aux); 774 luaL_newlib(L, rocklib);
775 luaL_setfuncs(L, rocklib_aux, 0);
763 776
764 RB_CONSTANT(HZ); 777 RB_CONSTANT(HZ);
765 778
@@ -797,7 +810,6 @@ LUALIB_API int luaopen_rock(lua_State *L)
797 RB_STRING_CONSTANT(PLUGIN_DATA_DIR); 810 RB_STRING_CONSTANT(PLUGIN_DATA_DIR);
798 RB_STRING_CONSTANT(VIEWERS_DATA_DIR); 811 RB_STRING_CONSTANT(VIEWERS_DATA_DIR);
799 812
800 rli_init(L);
801 813
802 return 1; 814 return 1;
803} 815}