Mercurial > hg > octave-avbm
changeset 7824:adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Fri, 08 Feb 2008 16:46:34 +0100 |
parents | feaaf725c54f |
children | 13871b7de124 |
files | src/ChangeLog src/graphics.cc src/graphics.h.in |
diffstat | 3 files changed, 36 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -8,6 +8,14 @@ before executing a callback. (root_figure::properties::set_callbackobject): Implement accessor. + * graphics.h.in (root_figure::properties::callbackobject): + New root property. + (root_figure::properties::cbo_stack): New field. + * graphics.cc (xset_gcbo, xreset_gcbo): New utility functions. + (execute_callback): Set callbackobject property in root object + before executing a callback. + (root_figure::properties::set_callbackobject): Implement accessor. + * graphics.h.in (class root_figure::properties, class line::properties, class text::properties, class image::properties, class patch::properties, @@ -1858,6 +1866,14 @@ (get_user_input): Don't process input_buf if there is an error. Call reset_error_handler instead of setting error_state to 0. +2008-02-08 Michael Goffioul <michael.goffioul@gmail.com> + + * graphics.h.in (callback_property::execute): New static + helper method (useful to execute callbacks by name). + * graphics.cc (callback_property::execute): Likewise. + (execute_callback): Avoid undefined argument when executing + callback. Do not use arguments when the callback is a string. + 2008-02-07 John W. Eaton <jwe@octave.org> * ov-range.h (octave_range::sort): New functions.
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -200,7 +200,10 @@ octave_function *fcn = 0; args(0) = h.as_octave_value (); - args(1) = data; + if (data.is_defined ()) + args(1) = data; + else + args(1) = Matrix (); unwind_protect::begin_frame ("execute_callback"); unwind_protect::add (xreset_gcbo); @@ -213,14 +216,10 @@ fcn = cb.function_value (); else if (cb.is_string ()) { + int status; std::string s = cb.string_value (); - octave_value f = symbol_table::find_function (s); - int status; - - if (f.is_defined ()) - fcn = f.function_value (); - else - eval_string (s, false, status); + + eval_string (s, false, status); } else if (cb.is_cell () && cb.length () > 0 && (cb.rows () == 1 || cb.columns () == 1) @@ -562,6 +561,14 @@ execute_callback (callback, get_parent (), data); } +void +callback_property::execute (const octave_value& cb, const graphics_handle& h, + const octave_value& data) +{ + if (cb.is_defined () && ! cb.is_empty ()) + execute_callback (cb, h, data); +} + // --------------------------------------------------------------------- void
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -985,6 +985,11 @@ OCTINTERP_API void execute (const octave_value& data = octave_value ()) const; + OCTINTERP_API static + void execute (const octave_value& cb, const graphics_handle& h, + const octave_value& data = octave_value ()); + + callback_property& operator = (const octave_value& val) { set (val);