Simple typemap example in swig java

Posted by celil on Stack Overflow See other posts from Stack Overflow or by celil
Published on 2010-05-12T04:00:20Z Indexed on 2010/05/12 4:04 UTC
Read the original article Hit count: 357

Filed under:
|
|
|

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);

© Stack Overflow or respective owner

Related posts about swig

Related posts about java