Changeset 3b9ca71


Ignore:
Timestamp:
Feb 19, 2013, 8:29:38 PM (8 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master
Children:
4584d1f
Parents:
69f74c2
git-author:
David Benjamin <davidben@mit.edu> (06/09/12 23:16:53)
git-committer:
David Benjamin <davidben@mit.edu> (02/19/13 20:29:38)
Message:
Allow perl variables to participate in argumentless set/unset
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    r353719a r3b9ca71  
    16041604  if (v == NULL) {
    16051605    if (!silent) owl_function_error("Unknown variable '%s'", var);
    1606   } else if (requirebool && owl_variable_get_type(v) != OWL_VARIABLE_BOOL) {
    1607     // FIXME: The above won't work when we make perl variables OWL_VARIABLE_SV
     1606  } else if (requirebool && !v->takes_on_off) {
    16081607    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
    16091608  } else {
     
    16341633  if (v == NULL) {
    16351634    if (!silent) owl_function_error("Unknown variable '%s'", var);
    1636   } else if (owl_variable_get_type(v) != OWL_VARIABLE_BOOL) {
    1637     // FIXME: The above won't work when we make perl variables OWL_VARIABLE_SV
     1635  } else if (!v->takes_on_off) {
    16381636    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
    16391637  } else {
  • owl.h

    r69f74c2 r3b9ca71  
    239239  char *summary;                /* summary of usage */
    240240  char *description;            /* detailed description */
     241  bool takes_on_off;            /* allow passing on/off in argument-less set/unset */
    241242  GClosure *set_fromstring_fn;
    242243                                /* sets the variable to a value
  • perl/lib/BarnOwl.pm

    r69f74c2 r3b9ca71  
    426426
    427427sub new_variable_int {
    428     unshift @_, 0, "<int>", sub { "$_[0]" }, # to string
    429                             sub { $_[0] =~ /^-?[0-9]+$/ }, # validate
    430                             sub { 0 + $_[0] }; # from string
     428    unshift @_, 0, "<int>", 0, sub { "$_[0]" }, # to string
     429                               sub { $_[0] =~ /^-?[0-9]+$/ }, # validate
     430                               sub { 0 + $_[0] }; # from string
    431431    goto \&_new_variable;
    432432}
    433433
    434434sub new_variable_bool {
    435     unshift @_, 0, "on,off", sub { $_[0] ? "on" : "off" }, # to string
    436                              sub { $_[0] eq "on" || $_[0] eq "off" }, # validate
    437                              sub { $_[0] eq "on" }; # from string
     435    unshift @_, 0, "on,off", 1, sub { $_[0] ? "on" : "off" }, # to string
     436                                sub { $_[0] eq "on" || $_[0] eq "off" }, # validate
     437                                sub { $_[0] eq "on" }; # from string
    438438    goto \&_new_variable;
    439439}
    440440
    441441sub new_variable_string {
    442     unshift @_, "", "<string>", sub { $_[0] }, # to string
    443                                 sub { 1 }, # validate
    444                                 sub { $_[0] }; # from string
     442    unshift @_, "", "<string>", 0, sub { $_[0] }, # to string
     443                                   sub { 1 }, # validate
     444                                   sub { $_[0] }; # from string
    445445    goto \&_new_variable;
    446446}
     
    449449    my $default_default = shift;
    450450    my $validsettings = shift;
     451    my $takes_on_off = shift;
    451452    my $tostring_fn = shift;
    452453    my $validate_fn = shift;
     
    473474
    474475    BarnOwl::Internal::new_variable($name, $args{summary}, $args{description}, $validsettings,
    475                                     $get_tostring_fn, $set_fromstring_fn, undef);
     476                                    $takes_on_off, $get_tostring_fn, $set_fromstring_fn, undef);
    476477}
    477478
  • perlglue.xs

    r69f74c2 r3b9ca71  
    406406
    407407void
    408 new_variable(name, summary, description, validsettings, get_tostring_fn, set_fromstring_fn, data)
     408new_variable(name, summary, description, validsettings, takes_on_off, get_tostring_fn, set_fromstring_fn, data)
    409409    const char *name
    410410    const char *summary
    411411    const char *description
    412412    const char *validsettings
     413    int takes_on_off
    413414    SV *get_tostring_fn
    414415    SV *set_fromstring_fn
     
    426427
    427428        owl_variable_dict_newvar_other(owl_global_get_vardict(&g),
    428                                        name, summary, description, validsettings,
     429                                       name, summary, description, validsettings, takes_on_off,
    429430                                       perl_closure_new(get_tostring_fn, data, false),
    430431                                       perl_closure_new(set_fromstring_fn, data, false));
  • variable.c

    r69f74c2 r3b9ca71  
    619619    newvar = g_new0(owl_variable, 1);
    620620    newvar->type = init_params->type;
     621    newvar->takes_on_off = (newvar->type == OWL_VARIABLE_BOOL);
    621622    /* strdup all the strings so we can delete them consistently. */
    622623    newvar->name = g_strdup(init_params->name);
     
    680681}
    681682
    682 void owl_variable_dict_newvar_other(owl_vardict *vd, const char *name, const char *summary, const char *description, const char *validsettings, GClosure *get_tostring_fn, GClosure *set_fromstring_fn)
     683void owl_variable_dict_newvar_other(owl_vardict *vd, const char *name, const char *summary, const char *description, const char *validsettings, bool takes_on_off, GClosure *get_tostring_fn, GClosure *set_fromstring_fn)
    683684{
    684685  owl_variable *var = g_new0(owl_variable, 1);
     
    687688  var->description = g_strdup(description);
    688689  var->validsettings = g_strdup(validsettings);
     690  var->takes_on_off = takes_on_off;
    689691
    690692  var->get_tostring_fn = g_closure_ref(get_tostring_fn);
Note: See TracChangeset for help on using the changeset viewer.