release 1.14pre1
[descalc.git] / 28_stack.pm
1 # improved stack functionality for DCT, by Shiar
2
3 # 1.13.0 200411042045 - added swap and stack from main
4 #                     - renamed to "stack"
5 #                     - stack cycle would crash with undefined stack
6 # 1.10.1 200410150045 - set initial value to prevent crash when no undos set
7 # 1.10.0 200410150000 - single-level undo from main
8
9 use strict;
10 use warnings;
11
12 my $undo = [];  # stack backup
13 my $stackpos = 0;  # position of stack browser
14
15 push @{$hook{preaction}}, sub {
16         if ($_[0] >= 0) {
17                 $undo = [@stack];  # backup stack
18                 $stackpos = 0;  # reset position of stack navigation
19         } # stack-modifying operations (type>=0)
20 }; # preaction
21
22 $action{undo}  = [-1, sub { ($undo, @stack) = ([@stack], @$undo) }]; # undo/redo
23
24 $action{swap}  = [ 2, sub { reverse @_ }]; # swap x<->y
25
26 $action{stack} = [-2, sub {
27         $stackpos %= @stack if @stack;  # cycle
28         $val{i} = $stack[$stackpos++];
29 }]; # stack
30
31 return {
32         author  => "Shiar",
33         title   => "stack functions",
34         version => "1.13",
35 };
36