diff options
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
| -rw-r--r-- | apps/plugins/lua/rocklib.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 27c1177..f214aca 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c @@ -156,7 +156,19 @@ static int rli_tostring(lua_State *L) return 1; } -static const struct luaL_reg rli_lib [] = +int rli_checkboolean (lua_State *L, int narg) { + int b = lua_toboolean(L, narg); + if (b == 0) + luaL_checktype(L, narg, LUA_TBOOLEAN); + return b; +} + + +int rli_optboolean (lua_State *L, int narg, int def) { + return luaL_opt(L, rli_checkboolean, narg, def); +} + +static const struct luaL_Reg rli_lib [] = { {"__tostring", rli_tostring}, {"set", rli_set}, @@ -472,8 +484,8 @@ RB_WRAP(read_bmp_file) { struct bitmap bm; const char* filename = luaL_checkstring(L, 1); - bool dither = luaL_optboolean(L, 2, true); - bool transparent = luaL_optboolean(L, 3, false); + bool dither = rli_optboolean(L, 2, true); + bool transparent = rli_optboolean(L, 3, false); int format = FORMAT_NATIVE; if(dither) @@ -516,7 +528,7 @@ static void fill_text_message(lua_State *L, struct text_message * message, { int i; luaL_checktype(L, pos, LUA_TTABLE); - int n = luaL_getn(L, pos); + int n = lua_rawlen(L, pos); const char **lines = (const char**) tlsf_malloc(n * sizeof(const char*)); if(lines == NULL) luaL_error(L, "Can't allocate %d bytes!", n * sizeof(const char*)); @@ -565,7 +577,7 @@ RB_WRAP(do_menu) luaL_checktype(L, 2, LUA_TTABLE); start_selected = luaL_optint(L, 3, 0); - n = luaL_getn(L, 2); + n = lua_rawlen(L, 2); items = (const char**) tlsf_malloc(n * sizeof(const char*)); if(items == NULL) luaL_error(L, "Can't allocate %d bytes!", n * sizeof(const char*)); @@ -758,8 +770,9 @@ extern const luaL_Reg rocklib_aux[]; */ LUALIB_API int luaopen_rock(lua_State *L) { - luaL_register(L, LUA_ROCKLIBNAME, rocklib); - luaL_register(L, LUA_ROCKLIBNAME, rocklib_aux); + rli_init(L); + luaL_newlib(L, rocklib); + luaL_setfuncs(L, rocklib_aux, 0); RB_CONSTANT(HZ); @@ -797,7 +810,6 @@ LUALIB_API int luaopen_rock(lua_State *L) RB_STRING_CONSTANT(PLUGIN_DATA_DIR); RB_STRING_CONSTANT(VIEWERS_DATA_DIR); - rli_init(L); return 1; } |