Changeset 3b9ca71
- Timestamp:
- Feb 19, 2013, 8:29:38 PM (10 years ago)
- 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)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
r353719a r3b9ca71 1604 1604 if (v == NULL) { 1605 1605 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) { 1608 1607 if (!silent) owl_function_error("Variable '%s' is not a boolean", var); 1609 1608 } else { … … 1634 1633 if (v == NULL) { 1635 1634 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) { 1638 1636 if (!silent) owl_function_error("Variable '%s' is not a boolean", var); 1639 1637 } else { -
owl.h
r69f74c2 r3b9ca71 239 239 char *summary; /* summary of usage */ 240 240 char *description; /* detailed description */ 241 bool takes_on_off; /* allow passing on/off in argument-less set/unset */ 241 242 GClosure *set_fromstring_fn; 242 243 /* sets the variable to a value -
perl/lib/BarnOwl.pm
r69f74c2 r3b9ca71 426 426 427 427 sub new_variable_int { 428 unshift @_, 0, "<int>", sub { "$_[0]" }, # to string429 sub { $_[0] =~ /^-?[0-9]+$/ }, # validate430 sub { 0 + $_[0] }; # from string428 unshift @_, 0, "<int>", 0, sub { "$_[0]" }, # to string 429 sub { $_[0] =~ /^-?[0-9]+$/ }, # validate 430 sub { 0 + $_[0] }; # from string 431 431 goto \&_new_variable; 432 432 } 433 433 434 434 sub new_variable_bool { 435 unshift @_, 0, "on,off", sub { $_[0] ? "on" : "off" }, # to string436 sub { $_[0] eq "on" || $_[0] eq "off" }, # validate437 sub { $_[0] eq "on" }; # from string435 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 438 438 goto \&_new_variable; 439 439 } 440 440 441 441 sub new_variable_string { 442 unshift @_, "", "<string>", sub { $_[0] }, # to string443 sub { 1 }, # validate444 sub { $_[0] }; # from string442 unshift @_, "", "<string>", 0, sub { $_[0] }, # to string 443 sub { 1 }, # validate 444 sub { $_[0] }; # from string 445 445 goto \&_new_variable; 446 446 } … … 449 449 my $default_default = shift; 450 450 my $validsettings = shift; 451 my $takes_on_off = shift; 451 452 my $tostring_fn = shift; 452 453 my $validate_fn = shift; … … 473 474 474 475 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); 476 477 } 477 478 -
perlglue.xs
r69f74c2 r3b9ca71 406 406 407 407 void 408 new_variable(name, summary, description, validsettings, get_tostring_fn, set_fromstring_fn, data)408 new_variable(name, summary, description, validsettings, takes_on_off, get_tostring_fn, set_fromstring_fn, data) 409 409 const char *name 410 410 const char *summary 411 411 const char *description 412 412 const char *validsettings 413 int takes_on_off 413 414 SV *get_tostring_fn 414 415 SV *set_fromstring_fn … … 426 427 427 428 owl_variable_dict_newvar_other(owl_global_get_vardict(&g), 428 name, summary, description, validsettings, 429 name, summary, description, validsettings, takes_on_off, 429 430 perl_closure_new(get_tostring_fn, data, false), 430 431 perl_closure_new(set_fromstring_fn, data, false)); -
variable.c
r69f74c2 r3b9ca71 619 619 newvar = g_new0(owl_variable, 1); 620 620 newvar->type = init_params->type; 621 newvar->takes_on_off = (newvar->type == OWL_VARIABLE_BOOL); 621 622 /* strdup all the strings so we can delete them consistently. */ 622 623 newvar->name = g_strdup(init_params->name); … … 680 681 } 681 682 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)683 void 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) 683 684 { 684 685 owl_variable *var = g_new0(owl_variable, 1); … … 687 688 var->description = g_strdup(description); 688 689 var->validsettings = g_strdup(validsettings); 690 var->takes_on_off = takes_on_off; 689 691 690 692 var->get_tostring_fn = g_closure_ref(get_tostring_fn);
Note: See TracChangeset
for help on using the changeset viewer.