|
|
@ -4,6 +4,8 @@ tstylesheet { |
|
|
|
template "module" { |
|
|
|
document("py_module.pybind11", "text") { |
|
|
|
|| |
|
|
|
namespace py = pybind11; |
|
|
|
|
|
|
|
// INSERT COOL ASCII ART HERE |
|
|
|
// METHOD |
|
|
|
`` apply "method" |
|
|
@ -37,19 +39,19 @@ tstylesheet { |
|
|
|
[] |
|
|
|
( |
|
|
|
``apply "use", mode="arg_list_from_py" |
|
|
|
) -> pybind11::tuple |
|
|
|
) -> py::tuple |
|
|
|
{ |
|
|
|
``apply "return", mode="create" |
|
|
|
``apply "use", mode="create_args_c" |
|
|
|
`apply "return", mode="assign"`::«@name»( |
|
|
|
``apply "use", mode="arg_list_c" |
|
|
|
); |
|
|
|
return pybind11::make_tuple( |
|
|
|
return py::make_tuple( |
|
|
|
`apply "return", mode="return"``if "count(use)>0" > ,` |
|
|
|
``apply "use", mode="return_args_as_tuple" |
|
|
|
); |
|
|
|
}, |
|
|
|
pybind11::return_value_policy::copy); |
|
|
|
py::return_value_policy::copy); |
|
|
|
|| |
|
|
|
} |
|
|
|
|
|
|
@ -67,7 +69,7 @@ tstylesheet { |
|
|
|
const "type", "@type"; |
|
|
|
choose { |
|
|
|
when "contains($type,'void')" { |
|
|
|
> pybind11::none() |
|
|
|
> py::none() |
|
|
|
} otherwise { |
|
|
|
choose { |
|
|
|
when "contains($type,'*')" { |
|
|
@ -174,8 +176,8 @@ tstylesheet { |
|
|
|
|
|
|
|
template "struct" { |
|
|
|
|| |
|
|
|
pybind11::class_<«@name»>(m, "«@name»") |
|
|
|
.def(pybind11::init([]() { return «@name»(); })) |
|
|
|
py::class_<«@name»>(m, "«@name»") |
|
|
|
.def(py::init([]() { return «@name»(); })) |
|
|
|
|| |
|
|
|
apply "field" { |
|
|
|
with "structname", "@name" |
|
|
@ -185,40 +187,86 @@ tstylesheet { |
|
|
|
| |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template "field" { |
|
|
|
param "structname"; |
|
|
|
|| |
|
|
|
.def_property("«@name»", |
|
|
|
[](::«$structname» &obj) -> «@type» { |
|
|
|
//cout << "«$structname» ::«@name»: getter called" << endl; |
|
|
|
return obj.«@name»; |
|
|
|
}, |
|
|
|
|| |
|
|
|
param "name", "@name"; |
|
|
|
param "type", "@type"; |
|
|
|
const "array_type", "substring-before($type, '[')"; |
|
|
|
const "array_len", "substring-before(substring-after($type, '['),']')"; |
|
|
|
|
|
|
|
choose { |
|
|
|
when "@type = 'const char *'" { |
|
|
|
|| |
|
|
|
[](::«$structname» &obj, «@type» cstr) -> void { |
|
|
|
//cout << "«$structname»::«@name»: setter called" << cstr << endl; |
|
|
|
obj.«@name» = strdup(cstr); |
|
|
|
}, |
|
|
|
pybind11::return_value_policy::copy) |
|
|
|
|| |
|
|
|
when "string-length($array_len) > 0" { |
|
|
|
|| |
|
|
|
.def_property("«$name»", |
|
|
|
[](::«$structname» &obj) -> py::list { |
|
|
|
//cout << "«$structname»::«$name»: getter called" << endl; |
|
|
|
py::list l; |
|
|
|
for(int i=0; i < «$array_len»; ++i) { |
|
|
|
l.append(obj.«$name»[i]); |
|
|
|
} |
|
|
|
return l; |
|
|
|
}, |
|
|
|
[](::«$structname» &obj, py::list val) -> void { |
|
|
|
// cout << "«$structname»::«$name»: getter called" << endl; |
|
|
|
if(val.size() <= 0) { |
|
|
|
// empty array given, doing nothing (static c array cant be cleared) |
|
|
|
} else { |
|
|
|
int cpy_amt = std::min(static_cast<int>(val.size()), «$array_len»); |
|
|
|
bool isUnitypedArrayOf = true; |
|
|
|
for(int i=0; i < cpy_amt; ++i) { |
|
|
|
if (!py::isinstance<«$array_type»>(val[i])) { |
|
|
|
isUnitypedArrayOf = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!isUnitypedArrayOf) { |
|
|
|
cout << "«$structname»::«$name» - setter error: is not a unityped array of type «$array_type»" << std::endl; |
|
|
|
} else { |
|
|
|
for(int i=0; i < cpy_amt; ++i) { |
|
|
|
obj.«$name»[i] = val[i].cast<«$array_type»>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
py::return_value_policy::copy) |
|
|
|
|
|
|
|
|| |
|
|
|
} otherwise { |
|
|
|
|| |
|
|
|
[](::«$structname» &obj, «@type» val) -> void { |
|
|
|
//cout << "«$structname»::«@name»: setter called" << endl; |
|
|
|
obj.«@name» = val; |
|
|
|
}, |
|
|
|
pybind11::return_value_policy::copy) |
|
|
|
|| |
|
|
|
.def_property("«@name»", |
|
|
|
[](::«$structname» &obj) -> «$type» { |
|
|
|
//cout << "«$structname» ::«@name»: getter called" << endl; |
|
|
|
return obj.«@name»; |
|
|
|
}, |
|
|
|
|| |
|
|
|
choose { |
|
|
|
when "$type = 'const char *'" { |
|
|
|
|| |
|
|
|
[](::«$structname» &obj, «$type» cstr) -> void { |
|
|
|
//cout << "«$structname»::«@name»: setter called" << cstr << endl; |
|
|
|
obj.«@name» = strdup(cstr); |
|
|
|
}, |
|
|
|
py::return_value_policy::copy) |
|
|
|
|| |
|
|
|
} otherwise { |
|
|
|
|| |
|
|
|
[](::«$structname» &obj, «$type» val) -> void { |
|
|
|
//cout << "«$structname»::«@name»: setter called" << endl; |
|
|
|
obj.«@name» = val; |
|
|
|
}, |
|
|
|
py::return_value_policy::copy) |
|
|
|
|
|
|
|
|| |
|
|
|
|| |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
template "enum" { |
|
|
|
|| |
|
|
|
pybind11::enum_<::«@name»>(m, "«@name»") |
|
|
|
py::enum_<::«@name»>(m, "«@name»") |
|
|
|
``apply item |
|
|
|
; |
|
|
|
|
|
|
|