I'm new to tcl and swig, and am interfacing an existing c++ library to tcl via swig. I can load into swig successfully. Some of my apis take parameters of type int32_t, defined in . When I attempt to invoke these methods via tcl, I get a "TypeError in method ... argument 2 of type 'int32_t'. I do not know how to force the type of my second parameter to be compatible with what tcl expects. I've created an integer variable in tcl, but tcl has strict type checking and thinks that integer is not compatible with the int32_t parameter of the C++ method.
I've done plenty of googling but can't identify any resources for how user defined types (e.g. int32_t) in C++ can be mirrored/made compatible with tcl variables. I see that most tcl variables are string by default, but can be forced to be other types, such as integer, but don't see any way for tcl to create a type such as int32_t.
I tried various tcl syntax like {int32_t $var1} as maybe a cast, no joy. Also tried creating an int32_t object similar to how my class was created, e.g. int32_t var2, but tcl says that int32_t is an unknown command.
I also tried including cstdint in my .i file (this is where int32_t is defined). To get this to work, I had to specify the include path as part of the swig command line, as the swig preprocessor doesn't follow standard c search path info.
My question is somewhat similar to the question below, which didn't have a clear resolution and deals with enum constants, which may be different than the int32_t type defined in cstdint?
how to pass enum values from TCL script to C++ class using Swig
The question above mentions the use of typemaps, and that may be the solution I need? but it seems rather complex for such a simple interface problem?
Thanks for any assistance!
p.s. - I created a very simple example using the following code. I get the following error: Results
I tried to insert sample code but the stackoverflow feature for inserting code works terribly and basically wouldn't allow me to post it. Sorry.
Assuming that your int
is 32-bit, just include this at the beginning of your SWIG interface file:
%apply int { int32_t };