view examples/code/globaldemo.cc @ 31195:776446acdc7b

pkg.m: Show URL of source tarball(s) in verbose mode. * scripts/pkg/pkg.m: If downloading source tarballs with the "-forge" option, show the URL where they are downloaded from if verbose mode is on.
author Markus Mützel <markus.muetzel@gmx.de>
date Fri, 19 Aug 2022 08:54:05 +0200
parents 18fea1c5b21a
children
line wrap: on
line source

#include <octave/oct.h>
#include <octave/interpreter.h>

DEFMETHOD_DLD (globaldemo, interp, args, , "Global Demo")
{
  if (args.length () != 1)
    print_usage ();

  octave_value retval;

  std::string s = args(0).string_value ();

  octave::symbol_table& symtab = interp.get_symbol_table ();

  octave_value tmp = symtab.global_varval (s);

  if (tmp.is_defined ())
    retval = tmp;
  else
    retval = "Global variable not found";

  symtab.global_assign ("a", 42.0);

  return retval;
}