octave-maintainers
[Top][All Lists]
Advanced

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

Re: reconstructing m files from octave_function


From: Matt Flax
Subject: Re: reconstructing m files from octave_function
Date: Wed, 12 Dec 2012 13:18:17 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

Hi John,

The real implementation is using far more complex functions. The idea is to be able to alter certain parts of the function and save the altered version back to file for execution when the system has been shutdown and restarted.

I have chased up what you said below and SUCCESS !!!
Here is the first working version :

    % start octave and setup variables
    octave_main((int)cstr_arguments.size(), (char**)&cstr_arguments[0], 1);

    string name();
    string fileName("SystemConfig.m");
    string dirName("path/to/Config/");
    string dispatch_type, fcn_name("SystemConfig");

% load the function from file and get it into the octave_user_function form octave_function *fn=load_fcn_from_file (fileName, dirName, dispatch_type, fcn_name);
    octave_value tmp (fn);
    octave_fcn_handle *ofh= new octave_fcn_handle(tmp, fcn_name);
    octave_user_function *ouf=ofh->user_function_value(false);

    % save the function back to disk
    ofstream output("/tmp/test.txt");
    tree_print_code tpc(output);
    tpc.visit_octave_user_function (*ouf);
    output.close();

thanks everyone for their help !
Matt

On 12/11/2012 03:44 PM, John W. Eaton wrote:
On 11-Dec-2012, Matt Flax wrote:

| I would like to add this functionality, however I am leaving work next
| week and am not sure they will give me the time to implement it.
|
| I will try to fit it in.
|
| Matt
|
| On 12/11/2012 08:00 AM, Jordi Gutiérrez Hermoso wrote:
| > On 10 December 2012 21:01, Matt Flax <address@hidden> wrote:
| >> Has anyone got any idea on how to reconstruct an m file from an
| >> octave_function ?
| > This isn't currently possible. After Octave parses an m-file, its
| > internal representation discards most of the information you would
| > like to make it human-readable.
| >
| > If you have ideas how to add this functionality to the Octave parser,
| > I'd be interested to see your patches.

It used to be possible to print the parse tree and the type function
would do it.  I think most of the functionality is still there.

But based on your simple example, I don't see the point of what you
are trying to do.  Why not just write functions that take parameters
or use global variables to achieve the same thing?  Why write a new
function in text form?

jwe



reply via email to

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