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