wrapping question
Jim McNamara <[email protected]> Mon, 7 Jun 2021 20:34:24 -0400
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CAEMWCRtP0i=EbcTXdFY1=cmi2JoDv101O4vqBgz4vO20h3HJ4A@mail.gmail.com> |
Hi -
I have a question on wrapping a function. How can I use the 'wrapped code'
listed below in Tcl? jI am not understanding why wrapping this with tcl api
code is helping. I am interested in the mutated string. I can't see where
wrapping can save time. It is executing the c function, so what good is the
wrapper doing?
Please assist.
thanks!
// header
#include "tcl.h"
extern const int SPAM = 42;
extern void runVec();
extern int gcd(int x, int y);
extern void blist(char * b, int len);
// c function that compiles named blist
void blist(char *b, int len) {
// this code prints b value when entered into tclsh.
char * a = (char *) malloc(15);
memmove(a, b , 15);
b = a;
printf("%s", b);
}
// wrapped code
//sociTest1.i
%module sociTest1
%include <windows.i>
%include <std_string.i>
%include "std_vector.i"
/* Put headers and other declarations here */
%include <std_string.i>
%inline %{
#include "SOCITEST1.h"
%}
%include "SOCITEST1.h"
namespace std {
%template(vectorx) vector<std::string>;
// extern char* blist(char* b, int len);
/* Convert from Tcl --> C */
%typemap(in) int {
$1 = Tcl_GetIntFromObj($input);
}
/* Convert from C --> Tcl */
%typemap(out) int {
$result = Tcl_NewIntObj($1);
}
// start of mutated code typemaps X2
%typemap(in) (char *str, int len) {
char *temp;
temp = Tcl_GetStringFromObj($input,&$2);
$1 = (char *) malloc($2+1);
memmove($1,temp,$2);
}
/* Return the mutated string as a new object. */
%typemap(argout) (char *str, int len) {
Tcl_Obj *o;
o = Tcl_NewStringObj($1,$2);
Tcl_ListObjAppendElement(interp,$result,o);
free($1);
}
};
_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user