From de06a06351dfb8df1963033ec7e4fc69c796288a Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 26 Sep 2019 23:23:16 -0500 Subject: [PATCH] lua remove and consolidate some rb plugin functions removes some usless / duplicated functions removes atoi - lua tonumber() does this for you removes strlen - lua string.len does this for you removes system_memory_guard - if a device that actually implements system_memory_guard needs it we can add it back conditionally consolidates talk_number and talk_spell (on backend) consolidates talk_shutup and talk_force_shutup talk_shutup(bForce) Change-Id: Id132642f087975a7c132e99a668a41c977942b81 --- apps/plugins/lua/rocklib.c | 58 +++++++++++++++++++++++++++++++-- apps/plugins/lua/rocklib_aux.pl | 21 ++++++++++-- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 77b49dc8ec..e617f3e4bf 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c @@ -57,6 +57,7 @@ #define RB_WRAP(func) static int rock_##func(lua_State UNUSED_ATTR *L) #define SIMPLE_VOID_WRAPPER(func) RB_WRAP(func) { (void)L; func(); return 0; } +/* KERNEL */ RB_WRAP(current_tick) { lua_pushinteger(L, *rb->current_tick); @@ -77,6 +78,13 @@ RB_WRAP(schedule_cpu_boost) } #endif +RB_WRAP(sleep) +{ + unsigned ticks = (unsigned) lua_tonumber(L, 1); + rb->sleep(ticks); + return 0; +} + #ifdef HAVE_PRIORITY_SCHEDULING RB_WRAP(thread_set_priority) { @@ -847,8 +855,47 @@ RB_WRAP(read_mem) lua_replace(L, -3);/* stk pos 1 is no longer offset it is starting address */ return mem_read_write(L, address, maxsize, false); } + +/* will add this back if anyone finds a target that needs it */ +RB_WRAP(system_memory_guard) +{ + int newmode = (int) luaL_checkint(L, 1); + int result = rb->system_memory_guard(newmode); + lua_pushinteger(L, result); + return 1; +} #endif +/* SPEAKING */ +static int rock_talk(lua_State *L) +{ + int result; + bool enqueue = lua_toboolean(L, 2); + if (lua_isnumber(L, 1)) + { + long n = (long) lua_tonumber(L, 1); + result = rb->talk_number(n, enqueue); + } + else + { + const char* spell = luaL_checkstring(L, 1); + result = rb->talk_spell(spell, enqueue); + } + + lua_pushinteger(L, result); + return 1; +} + +RB_WRAP(talk_shutup) +{ + if (lua_toboolean(L, 1)) + rb->talk_force_shutup(); + else + rb->talk_shutup(); + return 0; +} + +/* MISC */ RB_WRAP(restart_lua) { /*close lua state, open a new lua state, load script @ filename */ @@ -859,17 +906,16 @@ RB_WRAP(restart_lua) return -1; } - #define RB_FUNC(func) {#func, rock_##func} #define RB_ALIAS(name, func) {name, rock_##func} static const luaL_Reg rocklib[] = { - /* Kernel */ + /* KERNEL */ RB_FUNC(current_tick), #ifdef HAVE_SCHEDULER_BOOSTCTRL RB_FUNC(schedule_cpu_boost), #endif - + RB_FUNC(sleep), #ifdef HAVE_PRIORITY_SCHEDULING RB_FUNC(thread_set_priority), #endif @@ -932,6 +978,12 @@ static const luaL_Reg rocklib[] = RB_FUNC(audio_next_track), RB_FUNC(audio_current_track), + /* SPEAKING */ + {"talk_number", rock_talk}, + {"talk_spell", rock_talk}, + RB_FUNC(talk_shutup), + + /* MISC */ RB_FUNC(restart_lua), {NULL, NULL} diff --git a/apps/plugins/lua/rocklib_aux.pl b/apps/plugins/lua/rocklib_aux.pl index 7202d8dff9..a618c3d360 100755 --- a/apps/plugins/lua/rocklib_aux.pl +++ b/apps/plugins/lua/rocklib_aux.pl @@ -21,7 +21,7 @@ # The purpose of this script is to automatically generate Lua wrappers for # (easily) portable C functions used in the Rockbox plugin API. -# It doesn't contain support for enums, structs or pointers (apart from char*). +# It doesn't contain support for structs or pointers (apart from char*). # # The output will be written to /apps/plugins/lua/rocklib_aux.c @@ -50,7 +50,8 @@ my @ported_functions; # These functions are excluded from automatically wrapping. This is useful if # you want to manually port them to Lua. The format is a standard Perl regular # expression. -my @forbidden_functions = ('^open$', +my @forbidden_functions = ('^atoi$', + '^open$', '^open_utf8$', '^close$', 'dcache', @@ -69,6 +70,7 @@ my @forbidden_functions = ('^open$', '^strip_extension$', '^create_numbered_filename$', '^s?+rand$', + '^strlen$', '^strl?+cpy$', '^strl?+cat$', 'strn?+casecmp$', @@ -103,11 +105,17 @@ my @forbidden_functions = ('^open$', '^pcm_(set_frequency|calculate_peaks)$', '^sound_(set|current|default|min|max|unit|pitch|val2phys)$', '^mixer_(set|get)_frequency$', - '^rock_plugin_get_current_filename$', + '^plugin_get_current_filename$', '^plugin_release_audio_buffer$', '^reload_directory$', '^set_current_file$', '^set_dirfilter$', + '^sleep$', + '^system_memory_guard$', + '^talk_number$', + '^talk_force_shutup$', + '^talk_spell$', + '^talk_shutup$', '^(trigger|cancel)_cpu_boost$', '^thread_', '^round_value_to_list32$'); @@ -185,6 +193,7 @@ EOF ; my %in_types = ('void' => \&in_void, + 'enum' => \&in_int, 'int' => \&in_int, 'unsigned' => \&in_int, 'unsignedint' => \&in_int, @@ -237,6 +246,12 @@ sub in_void return "\t(void)L;\n"; } +sub in_null +{ + my ($name, $type, $pos) = @_; + return sprintf("\t%s %s = NULL;\n", $type, $name, $type, $pos) +} + sub in_int { my ($name, $type, $pos) = @_;