diff --git a/libinterp/corefcn/toplev.cc b/libinterp/corefcn/toplev.cc --- a/libinterp/corefcn/toplev.cc +++ b/libinterp/corefcn/toplev.cc @@ -263,6 +263,29 @@ return retval; } +bool +octave_call_stack::all_scripts (void) const +{ + bool retval = true; + + const_iterator p = cs.end (); + + while (p != cs.begin ()) + { + const call_stack_elt& elt = *(--p); + + octave_function *f = elt.fcn; + + if (! f || ! f->is_user_script ()) + { + retval = false; + break; + } + } + + return retval; +} + // Use static fields for the best efficiency. // NOTE: C++0x will allow these two to be merged into one. static const char *bt_fieldnames[] = { "file", "name", "line", diff --git a/libinterp/corefcn/toplev.h b/libinterp/corefcn/toplev.h --- a/libinterp/corefcn/toplev.h +++ b/libinterp/corefcn/toplev.h @@ -206,6 +206,12 @@ return instance_ok () ? instance->do_caller_user_code (nskip) : 0; } + // Return TRUE if all elements on the call stack are scripts. + static bool all_scripts (void) + { + return instance_ok () ? instance->do_all_scripts () : false; + } + static void push (octave_function *f, symbol_table::scope_id scope = symbol_table::current_scope (), @@ -352,6 +358,8 @@ octave_user_code *do_caller_user_code (size_t nskip) const; + bool do_all_scripts (void) const; + void do_push (octave_function *f, symbol_table::scope_id scope, symbol_table::context_id context) {