[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: accessing workspace variables from .oct module?

From: Ben Sapp
Subject: Re: accessing workspace variables from .oct module?
Date: Mon, 08 Jan 2001 15:28:11 -0700

Nimrod Mesika wrote:
> Is reading/writing variables from the workspace of the calling .m
> function possible in an .oct module?

Yes, it is possible.  You will need to know the name of the variable you
want to access.   Below is a very simple example of doing this.   It
returns the value stored in a variable named "a" from the workspace. 

a sample session look like this:
octave:1> a = 1
a = 1
octave:2> sr
ans = 1
octave:3> a = [1,2,3]
a =

  1  2  3

octave:4> sr
ans =

  1  2  3

Source code:
#include <octave/config.h>
#include <string>

#include <octave/error.h>
#include <octave/input.h>
#include <octave/pager.h>
#include <octave/oct-obj.h>
#include <octave/utils.h>
#include <octave/gripes.h>
#include <octave/ov.h>
#include <octave/ov-usr-fcn.h>
#include <octave/ov-fcn.h>
#include <octave/pt-pr-code.h>
#include <octave/pt-stmt.h>
#include <octave/toplev.h>
#include <octave/unwind-prot.h>
#include <octave/variables.h>
#include <octave/defun-dld.h>
#include <octave/defun-int.h>

"Access a variable named \"a\" from the workspace.\n")
  std::string symbol_name = "a";
  symbol_record *sr = curr_sym_tab->lookup(symbol_name);

  octave_value tmp = sr->def();
  return tmp;

Ben Sapp                         Los Alamos National Laboratory
email: <mailto:address@hidden>   Phone: (505)667-3277
Fax:   (505)665-7920             URL:

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]