help-octave
[Top][All Lists]
Advanced

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

Re: using STL in .oct files


From: John W. Eaton
Subject: Re: using STL in .oct files
Date: Tue, 22 Aug 2000 01:29:01 -0500 (CDT)

On 12-Aug-2000, Nimrod Mesika <address@hidden> wrote:

| On Sat, Aug 12, 2000 at 09:11:55PM +0300, Nimrod Mesika wrote:
| > 
| > map<string, long> directory;
| > DEFUN_DLD (gg, args, ,"gg(str)ŠÜn")
| > {
| > 
| >     directory["Bogart"] = 1234567;
| >     directory["Bacall"] = 9876543;
| >     
| >     string name = args(0).string_value();
| > 
| >     if (directory.find(name) != directory.end()) 
| >         octave_stdout << "The phone number for " << name
| >         << " is " << directory[name] << "ŠÜn";
| > 
| >     return octave_value();
| > }
| 
| To follow my original post, using a simple type (a pointer) as a
| global does work:
| 
| typedef map<string, long> Directory;
| Directory *directory;
| 
| DEFUN_DLD (gg, args, ,"gg(str)ŠÜn")
| {
|     int nargin = args.length();
| 
|     if (nargin != 1) {
|        error("one string argument only!");
|        return octave_value();
|     }
| 
|     directory = new Directory;
| 
|     (*directory)["Bogart"] = 1234567;
|     (*directory)["Bacall"] =
|      
|      ...
| }
| 
| 
| Strange.

My guess is that constructors for global objects are not being called
when dlopen loads the .oct file on your system.  Doing that is really
beyond the scope of Octave.  I think your compiler/linker is supposed
to handle it.  As far as I know, it works correctly on Linux systems.
For example, the following code worked for me:

  #include <octave/oct.h>

  string tryme_string = "this is a string, eh?";

  DEFUN_DLD (tryme , , ,
    "tryme")
  {
    return octave_value (tryme_string);
  }

  $ mkoctfile tryme.cc
  $ octave
  GNU Octave, version 2.1.30 (i686-pc-linux-gnu).
  Copyright (C) 1996, 1997, 1998, 1999, 2000 John W. Eaton.
  This is free software with ABSOLUTELY NO WARRANTY.
  For details, type `warranty'.

  *** This is a development version of Octave.  Development releases
  *** are provided for people who want to help test, debug, and improve
  *** Octave.
  ***
  *** If you want a stable, well-tested version of Octave, you should be
  *** using one of the stable releases (when this development release
  *** was made, the latest stable version was 2.0.16).

  octave:1> tryme
  ans = this is a string, eh?

jwe



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

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



reply via email to

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