Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
7b8e032c
Commit
7b8e032c
authored
Aug 28, 2015
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a few basic number types
parent
43dbdfd0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
5 deletions
+12
-5
example/example5.cpp
+1
-1
example/example5.py
+2
-2
include/pybind/cast.h
+9
-2
No files found.
example/example5.cpp
View file @
7b8e032c
...
...
@@ -65,7 +65,7 @@ bool test_callback1(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
>
();
}
...
...
example/example5.py
View file @
7b8e032c
...
...
@@ -29,8 +29,8 @@ from example import Example5
def
func1
():
print
(
'Callback function 1 called!'
)
def
func2
(
a
,
b
,
c
):
print
(
'Callback function 2 called : '
+
str
(
a
)
+
", "
+
str
(
b
)
+
", "
+
str
(
c
))
def
func2
(
a
,
b
,
c
,
d
):
print
(
'Callback function 2 called : '
+
str
(
a
)
+
", "
+
str
(
b
)
+
", "
+
str
(
c
)
+
", "
+
str
(
d
))
return
c
class
MyCallback
(
Example5
):
...
...
include/pybind/cast.h
View file @
7b8e032c
...
...
@@ -222,11 +222,14 @@ protected:
template <> class type_caster<type> { \
public: \
bool load(PyObject *src, bool) { \
value = (type) from_type(src); \
if (value == (type) -1 && PyErr_Occurred()) { \
py_type py_value = from_type(src); \
if ((py_value == (py_type) -1 && PyErr_Occurred()) || \
py_value < std::numeric_limits<type>::min() || \
py_value > std::numeric_limits<type>::max()) { \
PyErr_Clear(); \
return false; \
} \
value = (type) py_value; \
return true; \
} \
static PyObject *cast(type src, return_value_policy
/* policy */
, PyObject *
/* parent */
) { \
...
...
@@ -235,6 +238,10 @@ protected:
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
(
uint32_t
,
unsigned
long
,
PyLong_AsUnsignedLong
,
PyLong_FromUnsignedLong
)
PYBIND_TYPE_CASTER_NUMBER
(
int64_t
,
PY_LONG_LONG
,
PyLong_AsLongLong
,
PyLong_FromLongLong
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment