changeset 32728:e36a95093ef6

maint: merge stable to default
author Rik <rik@octave.org>
date Thu, 11 Jan 2024 08:40:23 -0800
parents d970ec60aa64 (current diff) efcde0e04f5f (diff)
children 343b7e8d7f09
files
diffstat 1 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-oncleanup.cc	Wed Jan 10 17:54:55 2024 -0500
+++ b/libinterp/octave-value/ov-oncleanup.cc	Thu Jan 11 08:40:23 2024 -0800
@@ -205,13 +205,31 @@
 DEFUN (onCleanup, args, ,
        doc: /* -*- texinfo -*-
 @deftypefn {} {@var{obj} =} onCleanup (@var{function})
-Create a special object that executes a given function upon destruction.
+Create a special object that executes a given @var{function} upon destruction.
 
 If the object is copied to multiple variables (or cell or struct array
-elements) or returned from a function, @var{function} will be executed after
-clearing the last copy of the object.  Note that if multiple local onCleanup
-variables are created, the order in which they are called is unspecified.
-For similar functionality @xref{The unwind_protect Statement}.
+elements) or returned from a function, then @var{function} will be executed
+only after the last copy of the object is cleared.
+
+The input @var{function} is a handle to a function.  The handle may point to an
+anonymous function in order to directly place commands in the @code{onCleanup}
+call.
+
+Programming Note: If multiple local @code{onCleanup} variables are created, the
+order in which they are called is unspecified.  For similar functionality
+@xref{The unwind_protect Statement}.
+
+Example
+
+@example
+@group
+octave:1> trigger = onCleanup (@@() disp ('onCleanup was executed'));
+octave:2> clear trigger
+onCleanup was executed
+octave:3
+@end group
+@end example
+
 @end deftypefn */)
 {
   if (args.length () != 1)