[Scilab-Dev] To be able to develop Scilab interface in C++

Collette Yann ycollet at freesurf.fr
Fri Aug 29 18:45:55 CEST 2008


Hello,

I was thinking about something else.
First add some #ifdef to allows the compilation of a C++ interface via 
g++. I found that it was necessary to remove some cast to void * in 
CreateVar and to declare the main function as extern "C".
if you compile a C++ scilab interface via g++, g++ emit some warnings 
related to cast from strings to char * which are deprecated. So, soon, 
it will not be possible to compile using g++.
But my idea was to develop a "real" C++ interface like the one from octave.
Here is an example from the octave forge:  the leval function.
I will add some notes on the wiki

YC

// Copyright (C) 2002 Etienne Grossmann.  All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any
// later version.
//
// This is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.


#include "config.h"
#include <oct.h>
#include <octave/parse.h>


DEFUN_DLD (leval, args, nargout,
  "-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} leval (@var{name}, @var{list})\n\
Evaluate the function named @var{name}.  All the elements in @var{list}\n\
are passed on to the named function.  For example,\n\
\n\
@example\n\
leval (\"acos\", list (-1))\n\
     @result{} 3.1416\n\
@end example\n\
\n\
@noindent\n\
calls the function @code{acos} with the argument @samp{-1}.\n\
\n\
The function @code{leval} provides provides more flexibility than\n\
@code{feval} since arguments need not be hard-wired in the calling \n\
code. @seealso{feval and eval}\n\
@end deftypefn")
{
  octave_value_list retval;

  int nargin = args.length ();

  if (nargin == 2) 
    {
      std::string name = args(0).string_value ();
      if (error_state) 
	error ("leval: first argument must be a string");

      octave_value_list lst = args(1).list_value ();
      if (error_state) 
	error ("leval: second argument must be a list");

      retval = feval (name, lst, nargout);

    } 
  else
    print_usage ();

  return retval;
}


Sylvestre Ledru a écrit :
> Hello,
>
> I answer here because others might be interested.
>
> Yann, I noticed your change on the wiki:
> http://wiki.scilab.org/Ideas_of_development_for_Scilab?action=diff&rev2=36&rev1=35
>
> It is already possible and pretty easy. For example, if you have a look
> to this code:
> http://viewvc.scilab.org/bin/cgi/viewvc.cgi/trunk/scilab/modules/helptools/sci_gateway/cpp/sci_buildDoc.cpp?revision=27036&view=markup
>
> You will see this pure C++ code:
> 		if (doc->setOutputDirectory(outputDirectory)) 
> 		{
> 			doc->setWorkingLanguage(language);
> 			doc->setExportFormat(exportFormat);
> 			doc->process(masterXML, styleSheet);
> 			
> 			LhsVar(1) = 0;
> 			C2F(putlhsvar)();
> 		}
> [...]
>
> By the way, this code shows how easy it is to map a Java Method into
> Scilab (thanks to GIWS [1]).
>
> I started a doc on this:
> http://wiki.scilab.org/Call_a_Java_object_from_Scilab
> I will add examples when I have the time for it.
>
> Sylvestre
>
> [1] http://www.scilab.org/giws/
>
>   




More information about the dev mailing list