File: ilib_build_cpp.tst

package info (click to toggle)
scilab 5.2.2-9
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 334,832 kB
  • ctags: 52,586
  • sloc: xml: 526,945; ansic: 223,590; fortran: 163,080; java: 56,934; cpp: 33,840; tcl: 27,936; sh: 20,397; makefile: 9,908; ml: 9,451; perl: 1,323; cs: 614; lisp: 30
file content (64 lines) | stat: -rw-r--r-- 2,154 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - DIGITEO - Sylvestre LEDRU
// Copyright (C) 2009 - DIGITEO
//
//  This file is distributed under the same license as the Scilab package.
// =============================================================================

// <-- ENGLISH IMPOSED -->
// <-- JVM NOT MANDATORY -->

//Here with give a complete example on adding new primitive to Scilab
//create the procedure filese

//creating the interface file


i=['#include <string>'
'extern ""C"" {'
'#include ""stack-c.h""'
'int sci_cppfind(char *fname) {'
'  int m1 = 0, n1 = 0, l1;'
'  char *inputString1, *inputString2;'
'  int m2 = 0, n2 = 0, l2;'
'  int m3 = 0, n3 = 0;'
'  double *position = NULL; /* Where we will store the position */'
'  CheckRhs(2,2); /* Check the number of input argument */'
'  CheckLhs(1,1); /* Check the number of output argument */'
'  GetRhsVar(1, ""c"", &m1, &n1, &l1); /* Retrieve the first input argument */'
'  inputString1=cstk(l1);'
'  GetRhsVar(2, ""c"", &m2, &n2, &l2); /* Retrieve the second input argument */'
'  inputString2=cstk(l2);'
'  std::string myMessage (inputString1);'
'  std::string search (inputString2);'
'  m3=1;n3=1;'
'  position = new double[1];'
'  if (myMessage.find(search) != std::string::npos) {'
'    position[0] = myMessage.find(search); /* The actual operation */'
'  } else {'
'    position[0] = -1; /* Substring not found */'
'  }'
'  CreateVarFromPtr(Rhs+1,""d"",&m3,&n3,&position); /* Create the output argument */'
'  LhsVar(1) = Rhs+1;'
'  delete[] position;'
'  return 0;'
'}'
'}'];

mputl(i,'sci_cppfind.cxx');

//creating the shared library (a gateway, a Makefile and a loader are 
//generated. 

files=['sci_cppfind.cxx'];
ilib_build('foo',['cppfind','sci_cppfind'],files,[]);

// load the shared library 

exec loader.sce 

// Small test to see if the function is actually working.
if cppfind("my very long string","long") <> 8 pause, end
if cppfind("my very long string","very") <> 3 pause, end
if cppfind("my very long string","short") <> -1 pause, end