Reputation: 22490
I am trying to wrap a native C++ library using swig, and I am stuck at trying to convert time_t
in C, to long
in Java. I have successfully used swig with python, but so far I am unable to get the above typemap to work in Java.
In python it looks like this
%typemap(in) time_t
{
if (PyLong_Check($input))
$1 = (time_t) PyLong_AsLong($input);
else if (PyInt_Check($input))
$1 = (time_t) PyInt_AsLong($input);
else if (PyFloat_Check($input))
$1 = (time_t) PyFloat_AsDouble($input);
else {
PyErr_SetString(PyExc_TypeError,"Expected a large number");
return NULL;
}
}
%typemap(out) time_t
{
$result = PyLong_FromLong((long)$1);
}
I guess the in map from Java to C would be:
%typemap(in) time_t {
$1 = (time_t) $input;
}
How would I complete the out map from C to Java?
%typemap(out) time_t ???
Would I need typemaps like the ones below?
%typemap(jni)
%typemap(jtype)
%typemap(jstype)
I need this in order to wrap C functions like this:
time_t manipulate_time (time_t dt);
Upvotes: 5
Views: 5849
Reputation: 2421
You can simply do instead of using typemaps.
typedef long long time_t;
Upvotes: 0
Reputation: 14260
You should take a look at these sections of swig documentation:
There are also a lot of "examples" in the basic typemaps which are implemented for primitive types. You can find them in \swig\Lib\java\java.swg
I don't know if this working or not, but maybe something like this will suit your needs?
%typemap(jni) time_t "jlong"
%typemap(jtype) time_t "long"
%typemap(jstype) time_t "long"
%typemap(out) time_t %{ $result = (jlong)$1; %}
%typemap(in) time_t "(time_t)$input"
Upvotes: 8