lua rocklib_aux.pl support for enums

everything that would have been added has already been added or
needs more supporting functions so they've been excluded for the time being

Change-Id: I4ae4753c543287934702a3bd2eeccce5b032235d
This commit is contained in:
William Wilgus 2019-09-27 03:15:57 -05:00
parent bad739c0d8
commit 4fb783582f

View file

@ -21,7 +21,7 @@
# The purpose of this script is to automatically generate Lua wrappers for # The purpose of this script is to automatically generate Lua wrappers for
# (easily) portable C functions used in the Rockbox plugin API. # (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 <build_dir>/apps/plugins/lua/rocklib_aux.c # The output will be written to <build_dir>/apps/plugins/lua/rocklib_aux.c
@ -104,6 +104,7 @@ my @forbidden_functions = ('^atoi$',
'^pcm_(apply_settings|get_bytes_waiting)$', '^pcm_(apply_settings|get_bytes_waiting)$',
'^pcm_(set_frequency|calculate_peaks)$', '^pcm_(set_frequency|calculate_peaks)$',
'^sound_(set|current|default|min|max|unit|pitch|val2phys)$', '^sound_(set|current|default|min|max|unit|pitch|val2phys)$',
'^mixer_channel.*$',
'^mixer_(set|get)_frequency$', '^mixer_(set|get)_frequency$',
'^plugin_get_current_filename$', '^plugin_get_current_filename$',
'^plugin_release_audio_buffer$', '^plugin_release_audio_buffer$',
@ -112,12 +113,15 @@ my @forbidden_functions = ('^atoi$',
'^set_dirfilter$', '^set_dirfilter$',
'^sleep$', '^sleep$',
'^system_memory_guard$', '^system_memory_guard$',
'^system_sound_play$',
'^talk_number$', '^talk_number$',
'^talk_force_shutup$', '^talk_force_shutup$',
'^talk_spell$', '^talk_spell$',
'^talk_shutup$', '^talk_shutup$',
'^(trigger|cancel)_cpu_boost$', '^(trigger|cancel)_cpu_boost$',
'^thread_', '^thread_',
'^touchscreen_(get|set)_mode$',
'^viewportmanager_theme_undo$',
'^round_value_to_list32$'); '^round_value_to_list32$');
my $rocklib = sprintf("%s/rocklib.c", $ARGV[0]); my $rocklib = sprintf("%s/rocklib.c", $ARGV[0]);
@ -193,6 +197,7 @@ EOF
; ;
my %in_types = ('void' => \&in_void, my %in_types = ('void' => \&in_void,
'enum' => \&in_enum,
'int' => \&in_int, 'int' => \&in_int,
'unsigned' => \&in_int, 'unsigned' => \&in_int,
'unsignedint' => \&in_int, 'unsignedint' => \&in_int,
@ -216,6 +221,7 @@ my %in_types = ('void' => \&in_void,
'bool' => \&in_bool, 'bool' => \&in_bool,
'_Bool' => \&in_bool '_Bool' => \&in_bool
), %out_types = ('void' => \&out_void, ), %out_types = ('void' => \&out_void,
'enum' => \&out_enum,
'int' => \&out_int, 'int' => \&out_int,
'unsigned' => \&out_int, 'unsigned' => \&out_int,
'unsignedint' => \&out_int, 'unsignedint' => \&out_int,
@ -245,6 +251,12 @@ sub in_void
return "\t(void)L;\n"; return "\t(void)L;\n";
} }
sub in_enum
{
my ($name, $type, $pos) = @_;
return sprintf("\t%s %s = luaL_checkint(L, %d); /*(enum)*/\n", "int", $name, $pos);
}
sub in_int sub in_int
{ {
my ($name, $type, $pos) = @_; my ($name, $type, $pos) = @_;
@ -269,6 +281,12 @@ sub out_void
return sprintf("\t%s;\n\treturn 0;\n", $name); return sprintf("\t%s;\n\treturn 0;\n", $name);
} }
sub out_enum
{
my ($name, $type) = @_;
return sprintf("\t%s result = %s;\n\tlua_pushinteger(L, result);\n\treturn 1; /*(enum)*/\n", "int", $name);
}
sub out_int sub out_int
{ {
my ($name, $type) = @_; my ($name, $type) = @_;
@ -310,6 +328,7 @@ foreach my $function (@sorted_functions)
else else
{ {
$literal_type = trim($1), $name = trim($2), $type = trim($1); $literal_type = trim($1), $name = trim($2), $type = trim($1);
$type =~ s/^enum\s+.*/enum/g;
$type =~ s/(\s|const)//g; $type =~ s/(\s|const)//g;
if($name eq "") if($name eq "")
@ -339,6 +358,7 @@ foreach my $function (@sorted_functions)
# Check for supported return value # Check for supported return value
my $return = @$function{'return'}; my $return = @$function{'return'};
$return =~ s/^enum\s+.*/enum/g;
$return =~ s/(\s|const)//g; $return =~ s/(\s|const)//g;
#printf "/* %s: %s [%d] */\n", @$function{'name'}, $return, $valid; #printf "/* %s: %s [%d] */\n", @$function{'name'}, $return, $valid;
if(!defined $out_types{$return}) if(!defined $out_types{$return})