我正在嘗試使用swig打包本機C++庫,並且我試圖將C中的time_t
轉換爲Java中的long
。我已經用python成功地使用了swig,但到目前爲止,我無法獲得上述typemap在Java中的工作。 在蟒蛇看起來這Swig中的簡單類型映射示例java
%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);
}
我想在地圖上從Java到C是:
%typemap(in) time_t {
$1 = (time_t) $input;
}
我怎麼會在C完成了映射到Java?
%typemap(out) time_t ???
我需要像下面的類型映射嗎?
%typemap(jni)
%typemap(jtype)
%typemap(jstype)
我需要這一點是爲了包裝這樣的C函數:
time_t manipulate_time (time_t dt);