help-octave
[Top][All Lists]
Advanced

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

Re: doubts about functions declared in parse.h ...


From: Paul Kienzle
Subject: Re: doubts about functions declared in parse.h ...
Date: Sun, 13 Mar 2005 10:51:45 -0500


On Mar 13, 2005, at 10:25 AM, Alberto Francisco Martin Huertas wrote:
Hello. I'm interested into source a m file in a C++ DLF function with the
following behaviour:

$ cat script.m
a=3;
$ octave
octave:1> a=1
a=1
octave:2> exfun ("script.m", "a")
ans = 3
octave:3> a
a = 1

and the exfun C++ function you have provided to me has this behaviour:

$ cat script.m
a=3;
$ octave
octave:1> a=1
a=1
octave:2> exfun ("script.m", "a")
ans = 3
octave:3> a
a = 3

so I would like to source a script having a local scope in my C++ function. Is
that posible ?


You still haven't answered why you would want to do such a thing.

Is it too difficult to put "function a=f" at the beginning of your
script so that it will have its own local symbol table?

Regardless, you can do what you are asking for as an m-file:

octave:1> function ret=exfun(f,v); source(f); eval(['ret=',v,';']); end
octave:2> a=1;
octave:3> exfun('script.m','a')
ans = 3
octave:4> a
a = 1

If you insist on doing so in C++, then you will have to reproduce
the work octave does when it sets up a function call context, such
as pushing the current symbol table and creating a new one, then
call the function to load and execute the script, then clear the
new symbol table and pop the old one.  You will have to dig through
the octave sources to see how.

- Paul



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

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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