code('.${export}("${{self.name}}", &${cname}::${{self.cxx_name}})')
class PyBindMethod(PyBindExport):
- def __init__(self, name, cxx_name=None, args=None):
+ def __init__(self, name, cxx_name=None, args=None,
+ return_value_policy=None):
self.name = name
self.cxx_name = cxx_name if cxx_name else name
self.args = args
+ self.return_value_policy = return_value_policy
def _conv_arg(self, value):
if isinstance(value, bool):
raise TypeError("Unsupported PyBind default value type")
def export(self, code, cname):
+ arguments = [ '"${{self.name}}"', '&${cname}::${{self.cxx_name}}' ]
+ if self.return_value_policy:
+ arguments.append('pybind11::return_value_policy::'
+ '${{self.return_value_policy}}')
if self.args:
def get_arg_decl(arg):
if isinstance(arg, tuple):
else:
return 'py::arg("%s")' % arg
- code('.def("${{self.name}}", &${cname}::${{self.name}}, ')
- code(' ' + \
- ', '.join([ get_arg_decl(a) for a in self.args ]) + ')')
- else:
- code('.def("${{self.name}}", &${cname}::${{self.cxx_name}})')
+ arguments.extend(list([ get_arg_decl(a) for a in self.args ]))
+ code('.def(' + ', '.join(arguments) + ')')