summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2019-09-26 23:23:16 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2019-09-26 23:45:38 -0500
commitde06a06351dfb8df1963033ec7e4fc69c796288a (patch)
treea5516d6a3f51be7bc30ad6768ace5325852b7dbc /apps
parent5afdcdd46043481675a48891a071dbb1fea1ab4c (diff)
downloadrockbox-de06a06351dfb8df1963033ec7e4fc69c796288a.tar.gz
rockbox-de06a06351dfb8df1963033ec7e4fc69c796288a.zip
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
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/lua/rocklib.c58
-rwxr-xr-xapps/plugins/lua/rocklib_aux.pl21
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 @@
57#define RB_WRAP(func) static int rock_##func(lua_State UNUSED_ATTR *L) 57#define RB_WRAP(func) static int rock_##func(lua_State UNUSED_ATTR *L)
58#define SIMPLE_VOID_WRAPPER(func) RB_WRAP(func) { (void)L; func(); return 0; } 58#define SIMPLE_VOID_WRAPPER(func) RB_WRAP(func) { (void)L; func(); return 0; }
59 59
60/* KERNEL */
60RB_WRAP(current_tick) 61RB_WRAP(current_tick)
61{ 62{
62 lua_pushinteger(L, *rb->current_tick); 63 lua_pushinteger(L, *rb->current_tick);
@@ -77,6 +78,13 @@ RB_WRAP(schedule_cpu_boost)
77} 78}
78#endif 79#endif
79 80
81RB_WRAP(sleep)
82{
83 unsigned ticks = (unsigned) lua_tonumber(L, 1);
84 rb->sleep(ticks);
85 return 0;
86}
87
80#ifdef HAVE_PRIORITY_SCHEDULING 88#ifdef HAVE_PRIORITY_SCHEDULING
81RB_WRAP(thread_set_priority) 89RB_WRAP(thread_set_priority)
82{ 90{
@@ -847,8 +855,47 @@ RB_WRAP(read_mem)
847 lua_replace(L, -3);/* stk pos 1 is no longer offset it is starting address */ 855 lua_replace(L, -3);/* stk pos 1 is no longer offset it is starting address */
848 return mem_read_write(L, address, maxsize, false); 856 return mem_read_write(L, address, maxsize, false);
849} 857}
858
859/* will add this back if anyone finds a target that needs it */
860RB_WRAP(system_memory_guard)
861{
862 int newmode = (int) luaL_checkint(L, 1);
863 int result = rb->system_memory_guard(newmode);
864 lua_pushinteger(L, result);
865 return 1;
866}
850#endif 867#endif
851 868
869/* SPEAKING */
870static int rock_talk(lua_State *L)
871{
872 int result;
873 bool enqueue = lua_toboolean(L, 2);
874 if (lua_isnumber(L, 1))
875 {
876 long n = (long) lua_tonumber(L, 1);
877 result = rb->talk_number(n, enqueue);
878 }
879 else
880 {
881 const char* spell = luaL_checkstring(L, 1);
882 result = rb->talk_spell(spell, enqueue);
883 }
884
885 lua_pushinteger(L, result);
886 return 1;
887}
888
889RB_WRAP(talk_shutup)
890{
891 if (lua_toboolean(L, 1))
892 rb->talk_force_shutup();
893 else
894 rb->talk_shutup();
895 return 0;
896}
897
898/* MISC */
852RB_WRAP(restart_lua) 899RB_WRAP(restart_lua)
853{ 900{
854 /*close lua state, open a new lua state, load script @ filename */ 901 /*close lua state, open a new lua state, load script @ filename */
@@ -859,17 +906,16 @@ RB_WRAP(restart_lua)
859 return -1; 906 return -1;
860} 907}
861 908
862
863#define RB_FUNC(func) {#func, rock_##func} 909#define RB_FUNC(func) {#func, rock_##func}
864#define RB_ALIAS(name, func) {name, rock_##func} 910#define RB_ALIAS(name, func) {name, rock_##func}
865static const luaL_Reg rocklib[] = 911static const luaL_Reg rocklib[] =
866{ 912{
867 /* Kernel */ 913 /* KERNEL */
868 RB_FUNC(current_tick), 914 RB_FUNC(current_tick),
869#ifdef HAVE_SCHEDULER_BOOSTCTRL 915#ifdef HAVE_SCHEDULER_BOOSTCTRL
870 RB_FUNC(schedule_cpu_boost), 916 RB_FUNC(schedule_cpu_boost),
871#endif 917#endif
872 918 RB_FUNC(sleep),
873#ifdef HAVE_PRIORITY_SCHEDULING 919#ifdef HAVE_PRIORITY_SCHEDULING
874 RB_FUNC(thread_set_priority), 920 RB_FUNC(thread_set_priority),
875#endif 921#endif
@@ -932,6 +978,12 @@ static const luaL_Reg rocklib[] =
932 RB_FUNC(audio_next_track), 978 RB_FUNC(audio_next_track),
933 RB_FUNC(audio_current_track), 979 RB_FUNC(audio_current_track),
934 980
981 /* SPEAKING */
982 {"talk_number", rock_talk},
983 {"talk_spell", rock_talk},
984 RB_FUNC(talk_shutup),
985
986 /* MISC */
935 RB_FUNC(restart_lua), 987 RB_FUNC(restart_lua),
936 988
937 {NULL, NULL} 989 {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 @@
21 21
22# The purpose of this script is to automatically generate Lua wrappers for 22# The purpose of this script is to automatically generate Lua wrappers for
23# (easily) portable C functions used in the Rockbox plugin API. 23# (easily) portable C functions used in the Rockbox plugin API.
24# It doesn't contain support for enums, structs or pointers (apart from char*). 24# It doesn't contain support for structs or pointers (apart from char*).
25# 25#
26# The output will be written to <build_dir>/apps/plugins/lua/rocklib_aux.c 26# The output will be written to <build_dir>/apps/plugins/lua/rocklib_aux.c
27 27
@@ -50,7 +50,8 @@ my @ported_functions;
50# These functions are excluded from automatically wrapping. This is useful if 50# These functions are excluded from automatically wrapping. This is useful if
51# you want to manually port them to Lua. The format is a standard Perl regular 51# you want to manually port them to Lua. The format is a standard Perl regular
52# expression. 52# expression.
53my @forbidden_functions = ('^open$', 53my @forbidden_functions = ('^atoi$',
54 '^open$',
54 '^open_utf8$', 55 '^open_utf8$',
55 '^close$', 56 '^close$',
56 'dcache', 57 'dcache',
@@ -69,6 +70,7 @@ my @forbidden_functions = ('^open$',
69 '^strip_extension$', 70 '^strip_extension$',
70 '^create_numbered_filename$', 71 '^create_numbered_filename$',
71 '^s?+rand$', 72 '^s?+rand$',
73 '^strlen$',
72 '^strl?+cpy$', 74 '^strl?+cpy$',
73 '^strl?+cat$', 75 '^strl?+cat$',
74 'strn?+casecmp$', 76 'strn?+casecmp$',
@@ -103,11 +105,17 @@ my @forbidden_functions = ('^open$',
103 '^pcm_(set_frequency|calculate_peaks)$', 105 '^pcm_(set_frequency|calculate_peaks)$',
104 '^sound_(set|current|default|min|max|unit|pitch|val2phys)$', 106 '^sound_(set|current|default|min|max|unit|pitch|val2phys)$',
105 '^mixer_(set|get)_frequency$', 107 '^mixer_(set|get)_frequency$',
106 '^rock_plugin_get_current_filename$', 108 '^plugin_get_current_filename$',
107 '^plugin_release_audio_buffer$', 109 '^plugin_release_audio_buffer$',
108 '^reload_directory$', 110 '^reload_directory$',
109 '^set_current_file$', 111 '^set_current_file$',
110 '^set_dirfilter$', 112 '^set_dirfilter$',
113 '^sleep$',
114 '^system_memory_guard$',
115 '^talk_number$',
116 '^talk_force_shutup$',
117 '^talk_spell$',
118 '^talk_shutup$',
111 '^(trigger|cancel)_cpu_boost$', 119 '^(trigger|cancel)_cpu_boost$',
112 '^thread_', 120 '^thread_',
113 '^round_value_to_list32$'); 121 '^round_value_to_list32$');
@@ -185,6 +193,7 @@ EOF
185; 193;
186 194
187my %in_types = ('void' => \&in_void, 195my %in_types = ('void' => \&in_void,
196 'enum' => \&in_int,
188 'int' => \&in_int, 197 'int' => \&in_int,
189 'unsigned' => \&in_int, 198 'unsigned' => \&in_int,
190 'unsignedint' => \&in_int, 199 'unsignedint' => \&in_int,
@@ -237,6 +246,12 @@ sub in_void
237 return "\t(void)L;\n"; 246 return "\t(void)L;\n";
238} 247}
239 248
249sub in_null
250{
251 my ($name, $type, $pos) = @_;
252 return sprintf("\t%s %s = NULL;\n", $type, $name, $type, $pos)
253}
254
240sub in_int 255sub in_int
241{ 256{
242 my ($name, $type, $pos) = @_; 257 my ($name, $type, $pos) = @_;