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
9180519d
Commit
9180519d
authored
Jan 17, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added an example on using fancier kinds of default arguments
parent
1ae77fe4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
2 deletions
+28
-2
example/example11.cpp
+15
-0
example/example11.py
+5
-1
example/example11.ref
+8
-1
No files found.
example/example11.cpp
View file @
9180519d
...
@@ -8,11 +8,26 @@
...
@@ -8,11 +8,26 @@
*/
*/
#include "example.h"
#include "example.h"
#include <pybind11/stl.h>
void
kw_func
(
int
x
,
int
y
)
{
std
::
cout
<<
"kw_func(x="
<<
x
<<
", y="
<<
y
<<
")"
<<
std
::
endl
;
}
void
kw_func
(
int
x
,
int
y
)
{
std
::
cout
<<
"kw_func(x="
<<
x
<<
", y="
<<
y
<<
")"
<<
std
::
endl
;
}
void
kw_func4
(
const
std
::
vector
<
int
>
&
entries
)
{
std
::
cout
<<
"kw_func4: "
;
for
(
int
i
:
entries
)
std
::
cout
<<
i
<<
" "
;
std
::
cout
<<
endl
;
}
void
init_ex11
(
py
::
module
&
m
)
{
void
init_ex11
(
py
::
module
&
m
)
{
m
.
def
(
"kw_func"
,
&
kw_func
,
py
::
arg
(
"x"
),
py
::
arg
(
"y"
));
m
.
def
(
"kw_func"
,
&
kw_func
,
py
::
arg
(
"x"
),
py
::
arg
(
"y"
));
m
.
def
(
"kw_func2"
,
&
kw_func
,
py
::
arg
(
"x"
)
=
100
,
py
::
arg
(
"y"
)
=
200
);
m
.
def
(
"kw_func2"
,
&
kw_func
,
py
::
arg
(
"x"
)
=
100
,
py
::
arg
(
"y"
)
=
200
);
m
.
def
(
"kw_func3"
,
[](
const
char
*
)
{
},
py
::
arg
(
"data"
)
=
std
::
string
(
"Hello world!"
));
m
.
def
(
"kw_func3"
,
[](
const
char
*
)
{
},
py
::
arg
(
"data"
)
=
std
::
string
(
"Hello world!"
));
/* A fancier default argument */
std
::
vector
<
int
>
list
;
list
.
push_back
(
13
);
list
.
push_back
(
17
);
m
.
def
(
"kw_func4"
,
&
kw_func4
,
py
::
arg
(
"myList"
)
=
list
);
}
}
example/example11.py
View file @
9180519d
...
@@ -5,11 +5,12 @@ import pydoc
...
@@ -5,11 +5,12 @@ import pydoc
sys
.
path
.
append
(
'.'
)
sys
.
path
.
append
(
'.'
)
from
example
import
kw_func
,
kw_func2
,
kw_func3
from
example
import
kw_func
,
kw_func2
,
kw_func3
,
kw_func4
print
(
pydoc
.
render_doc
(
kw_func
,
"Help on
%
s"
))
print
(
pydoc
.
render_doc
(
kw_func
,
"Help on
%
s"
))
print
(
pydoc
.
render_doc
(
kw_func2
,
"Help on
%
s"
))
print
(
pydoc
.
render_doc
(
kw_func2
,
"Help on
%
s"
))
print
(
pydoc
.
render_doc
(
kw_func3
,
"Help on
%
s"
))
print
(
pydoc
.
render_doc
(
kw_func3
,
"Help on
%
s"
))
print
(
pydoc
.
render_doc
(
kw_func4
,
"Help on
%
s"
))
kw_func
(
5
,
10
)
kw_func
(
5
,
10
)
kw_func
(
5
,
y
=
10
)
kw_func
(
5
,
y
=
10
)
...
@@ -29,3 +30,6 @@ try:
...
@@ -29,3 +30,6 @@ try:
kw_func2
(
x
=
5
,
y
=
10
,
z
=
12
)
kw_func2
(
x
=
5
,
y
=
10
,
z
=
12
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"Caught expected exception: "
+
str
(
e
))
print
(
"Caught expected exception: "
+
str
(
e
))
kw_func4
()
kw_func4
(
myList
=
[
1
,
2
,
3
])
example/example11.ref
View file @
9180519d
...
@@ -11,7 +11,12 @@ kkww__ffuunncc22(...)
...
@@ -11,7 +11,12 @@ kkww__ffuunncc22(...)
Help on built-in function kw_func3
Help on built-in function kw_func3
kkww__ffuunncc33(...)
kkww__ffuunncc33(...)
Signature : (data : str = u'Hello world!') -> NoneType
Signature : (data : unicode = u'Hello world!') -> NoneType
Help on built-in function kw_func4
kkww__ffuunncc44(...)
Signature : (myList : list<int> = [13L, 17L]) -> NoneType
kw_func(x=5, y=10)
kw_func(x=5, y=10)
kw_func(x=5, y=10)
kw_func(x=5, y=10)
...
@@ -25,3 +30,5 @@ kw_func(x=5, y=10)
...
@@ -25,3 +30,5 @@ kw_func(x=5, y=10)
Caught expected exception: Incompatible function arguments. The following argument types are supported:
Caught expected exception: Incompatible function arguments. The following argument types are supported:
1. (x : int = 100L, y : int = 200L) -> NoneType
1. (x : int = 100L, y : int = 200L) -> NoneType
kw_func4: 13 17
kw_func4: 1 2 3
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