Changeset b54b06a


Ignore:
Timestamp:
Sep 30, 2011, 8:14:49 AM (10 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
cce9369
Parents:
c0e728a
git-author:
Jason Gross <jgross@mit.edu> (05/23/11 22:03:45)
git-committer:
Jason Gross <jgross@mit.edu> (09/30/11 08:14:49)
Message:
Added functionality for creating enum variables from perl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl.pm

    r7803326 rb54b06a  
    1717                    add_io_dispatch remove_io_dispatch
    1818                    new_command
    19                     new_variable_int new_variable_bool new_variable_string
     19                    new_variable_int new_variable_bool new_variable_string new_variable_enum
    2020                    quote redisplay);
    2121our %EXPORT_TAGS = (all => \@EXPORT_OK);
     
    389389=head2 new_variable_string NAME [{ARGS}]
    390390
    391 Add a new owl variable, either an int, a bool, or a string, with the
    392 specified name.
     391=head2 new_variable_enum NAME [{ARGS}]
     392
     393Add a new owl variable, either an int, a bool, a string, or an enum,
     394with the specified name.
    393395
    394396ARGS can optionally contain the following keys:
     
    398400=item default
    399401
    400 The default and initial value for the variable
     402The default and initial value for the variable.
     403Note that this should be a string value for an enum.
    401404
    402405=item summary
     
    407410
    408411A longer description of the function of the variable
     412
     413=item valid_settings
     414
     415A listref of valid setttings for the enum variable.
     416The settings must not contain any commas.
    409417
    410418=back
     
    425433    unshift @_, \&BarnOwl::Internal::new_variable_string, "";
    426434    goto \&_new_variable;
     435}
     436
     437sub new_variable_enum {
     438    my $name = shift;
     439    my $args = shift || {};
     440    my %args = (
     441        summary     => "",
     442        description => "",
     443        %{$args});
     444
     445    my @valid_settings =  @{$args{valid_settings}};
     446    if (defined $args{default}) {
     447        ($args{default}) = grep { $args{default} eq $valid_settings[$_] } 0..$#valid_settings; # turn the string default into a numerical default
     448    } else {
     449        $args{default} = 0;
     450    }
     451    $args{valid_settings} = join ",", @valid_settings;
     452
     453    BarnOwl::Internal::new_variable_enum($name, $args{default}, $args{summary}, $args{description}, $args{valid_settings});
    427454}
    428455
  • perlglue.xs

    re89ec48 rb54b06a  
    444444
    445445void
     446new_variable_enum(name, ival, summ, desc, validset)
     447        const char * name
     448        int ival
     449        const char * summ
     450        const char * desc
     451        const char * validset
     452        CODE:
     453        owl_variable_dict_newvar_enum(owl_global_get_vardict(&g),
     454                                      name,
     455                                      summ,
     456                                      desc,
     457                                      ival,
     458                                      validset);
     459
     460void
    446461start_edit(edit_type, line, callback)
    447462        const char *edit_type
Note: See TracChangeset for help on using the changeset viewer.