mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
added a few basic number types
This commit is contained in:
parent
43dbdfd0e7
commit
7b8e032c26
@ -65,7 +65,7 @@ bool test_callback1(py::object func) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int test_callback2(py::object func) {
|
int test_callback2(py::object func) {
|
||||||
py::object result = func.call("Hello", true, 5);
|
py::object result = func.call("Hello", 'x', true, 5);
|
||||||
return result.cast<int>();
|
return result.cast<int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ from example import Example5
|
|||||||
def func1():
|
def func1():
|
||||||
print('Callback function 1 called!')
|
print('Callback function 1 called!')
|
||||||
|
|
||||||
def func2(a, b, c):
|
def func2(a, b, c, d):
|
||||||
print('Callback function 2 called : ' + str(a) + ", " + str(b) + ", "+ str(c))
|
print('Callback function 2 called : ' + str(a) + ", " + str(b) + ", " + str(c) + ", "+ str(d))
|
||||||
return c
|
return c
|
||||||
|
|
||||||
class MyCallback(Example5):
|
class MyCallback(Example5):
|
||||||
|
@ -222,11 +222,14 @@ protected:
|
|||||||
template <> class type_caster<type> { \
|
template <> class type_caster<type> { \
|
||||||
public: \
|
public: \
|
||||||
bool load(PyObject *src, bool) { \
|
bool load(PyObject *src, bool) { \
|
||||||
value = (type) from_type(src); \
|
py_type py_value = from_type(src); \
|
||||||
if (value == (type) -1 && PyErr_Occurred()) { \
|
if ((py_value == (py_type) -1 && PyErr_Occurred()) || \
|
||||||
|
py_value < std::numeric_limits<type>::min() || \
|
||||||
|
py_value > std::numeric_limits<type>::max()) { \
|
||||||
PyErr_Clear(); \
|
PyErr_Clear(); \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
|
value = (type) py_value; \
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
static PyObject *cast(type src, return_value_policy /* policy */, PyObject * /* parent */) { \
|
static PyObject *cast(type src, return_value_policy /* policy */, PyObject * /* parent */) { \
|
||||||
@ -235,6 +238,10 @@ protected:
|
|||||||
PYBIND_TYPE_CASTER(type, #type); \
|
PYBIND_TYPE_CASTER(type, #type); \
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PYBIND_TYPE_CASTER_NUMBER(int8_t, long, PyLong_AsLong, PyLong_FromLong)
|
||||||
|
PYBIND_TYPE_CASTER_NUMBER(uint8_t, unsigned long, PyLong_AsUnsignedLong, PyLong_FromUnsignedLong)
|
||||||
|
PYBIND_TYPE_CASTER_NUMBER(int16_t, long, PyLong_AsLong, PyLong_FromLong)
|
||||||
|
PYBIND_TYPE_CASTER_NUMBER(uint16_t, unsigned long, PyLong_AsUnsignedLong, PyLong_FromUnsignedLong)
|
||||||
PYBIND_TYPE_CASTER_NUMBER(int32_t, long, PyLong_AsLong, PyLong_FromLong)
|
PYBIND_TYPE_CASTER_NUMBER(int32_t, long, PyLong_AsLong, PyLong_FromLong)
|
||||||
PYBIND_TYPE_CASTER_NUMBER(uint32_t, unsigned long, PyLong_AsUnsignedLong, PyLong_FromUnsignedLong)
|
PYBIND_TYPE_CASTER_NUMBER(uint32_t, unsigned long, PyLong_AsUnsignedLong, PyLong_FromUnsignedLong)
|
||||||
PYBIND_TYPE_CASTER_NUMBER(int64_t, PY_LONG_LONG, PyLong_AsLongLong, PyLong_FromLongLong)
|
PYBIND_TYPE_CASTER_NUMBER(int64_t, PY_LONG_LONG, PyLong_AsLongLong, PyLong_FromLongLong)
|
||||||
|
Loading…
Reference in New Issue
Block a user