From: Michael Schroeder Date: Fri, 21 Aug 2015 11:05:37 +0000 (+0200) Subject: tcl bindings: add solv::iter for iterator support X-Git-Tag: 0.6.12~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=359be93e1d490666e4dfb9133dfdc5cbd85f199d;p=thirdparty%2Flibsolv.git tcl bindings: add solv::iter for iterator support Usage: solv::iter var iterator code --- diff --git a/bindings/solv.i b/bindings/solv.i index 5476c7fd..9cca7002 100644 --- a/bindings/solv.i +++ b/bindings/solv.i @@ -3517,3 +3517,25 @@ rb_eval_string( return solver_alternative2str($self->solv, $self->type, $self->type == SOLVER_ALTERNATIVE_TYPE_RULE ? $self->rid : $self->dep_id, $self->from_id); } } + +#if defined(SWIGTCL) +%init %{ + Tcl_Eval(interp, +"proc solv::iter {varname iter body} {\n"\ +" while 1 {\n"\ +" set value [$iter __next__]\n"\ +" if {$value eq \"NULL\"} { break }\n"\ +" uplevel [list set $varname $value]\n"\ +" set code [catch {uplevel $body} result]\n"\ +" switch -exact -- $code {\n"\ +" 0 {}\n"\ +" 3 { return }\n"\ +" 4 {}\n"\ +" default { return -code $code $result }\n"\ +" }\n"\ +" }\n"\ +"}\n" + ); +%} +#endif +