File: ilib_build_cpp.win.dia.ref

package info (click to toggle)
scilab 5.3.3-10
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 330,656 kB
file content (109 lines) | stat: -rw-r--r-- 3,207 bytes parent folder | download
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// =============================================================================
// 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,[]);
   Generate a gateway file
   Generate a loader file
   Generate a Makefile: Makelib
   Running the makefile
   Compilation of sci_cppfind.cxx
   Building shared library (be patient)
   Generate a cleaner file
// load the shared library 
exec loader.sce 
 
// This file is released under the 3-clause BSD license. See COPYING-BSD.
 
// Generated by builder.sce : Please, do not edit this file
 
// ----------------------------------------------------------------------------
 
//
 
if win64() then
  warning(_("This module requires a Windows x86 platform."));
  return
end
 
//
 
foo_path = get_absolute_file_path('loader.sce');
 
//
 
// ulink previous function with same name
 
[bOK, ilib] = c_link('foo');
 
if bOK then
  ulink(ilib);
end
 
//
 
list_functions = [ 'cppfind';
];
 
addinter(foo_path + filesep() + 'foo' + getdynlibext(), 'foo', list_functions);
Shared archive loaded.
Link done.
 
// remove temp. variables on stack
 
clear foo_path;
 
clear bOK;
 
clear ilib;
 
clear list_functions;
 
// ----------------------------------------------------------------------------
 
// Small test to see if the function is actually working.
if cppfind("my very long string","long") <> 8 bugmes();quit;end
if cppfind("my very long string","very") <> 3 bugmes();quit;end
if cppfind("my very long string","short") <> -1 bugmes();quit;end