X-Git-Url: http://git.shiar.net/descalc.git/blobdiff_plain/4e1d9535fda6685e53ce570ca4e4cd6c260f55d3..090ac304afe801cb3e72ced0941ff2a874a98cc9:/28_stack.pm?ds=sidebyside diff --git a/28_stack.pm b/28_stack.pm new file mode 100644 index 0000000..6922747 --- /dev/null +++ b/28_stack.pm @@ -0,0 +1,36 @@ +# improved stack functionality for DCT, by Shiar + +# 1.13.0 200411042045 - added swap and stack from main +# - renamed to "stack" +# - stack cycle would crash with undefined stack +# 1.10.1 200410150045 - set initial value to prevent crash when no undos set +# 1.10.0 200410150000 - single-level undo from main + +use strict; +use warnings; + +my $undo = []; # stack backup +my $stackpos = 0; # position of stack browser + +push @{$hook{preaction}}, sub { + if ($_[0] >= 0) { + $undo = [@stack]; # backup stack + $stackpos = 0; # reset position of stack navigation + } # stack-modifying operations (type>=0) +}; # preaction + +$action{undo} = [-1, sub { ($undo, @stack) = ([@stack], @$undo) }]; # undo/redo + +$action{swap} = [ 2, sub { reverse @_ }]; # swap x<->y + +$action{stack} = [-2, sub { + $stackpos %= @stack if @stack; # cycle + $val{i} = $stack[$stackpos++]; +}]; # stack + +return { + author => "Shiar", + title => "stack functions", + version => "1.13", +}; +