Wednesday, March 28, 2012

gnocl::setOpts -new command

Sometimes I want to set a block of variables within procedure either as a set of defaults or as variables passed to a proc as options. Hitherto I've used a tcl proc to do this work but thought it high time to add this utility to the gnocl core. Ok, its not strictly graphics but it does make writing event handlers easier. Take the following for example:

doTagPopup -w %w -t %t -n %n -b %b -x %X -y %Y -matches OM|MANI|PADME|HUM|HRIH

The -w options can be used to create local variables. Here's a test snippet:

proc test-setOpts {args} { 
    gnocl::setOpts $args
    puts "$x $y $z"
    gnocl::setOpts [list j 4 k 5 l 6]
    puts "$j $k $l"

test-setOpts -x 1 -y 2 -z 3

In the first call the args string is parsed and values set en bloc. The leading '-' will be stripped away. In the second example, a paired list is given from which values will be set.

No comments: