release 1.14pre0
[descalc.git] / 28_stack.pm
diff --git a/28_stack.pm b/28_stack.pm
new file mode 100644 (file)
index 0000000..6922747
--- /dev/null
@@ -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",
+};
+