Add in an example/test for Python __pow__
- A test for the ternaryfunc builtin slot - Example of how to wrap C++ class for Python's pow
This commit is contained in:
parent
4d34d419b6
commit
bf85b6f7a9
2 changed files with 34 additions and 0 deletions
|
|
@ -226,3 +226,22 @@ void Dealloc2Destroyer(PyObject *v) {
|
|||
};
|
||||
%}
|
||||
|
||||
// Test 7 mapping to Python's pow
|
||||
%pybinoperator(__pow__, ANumber::power, ternaryfunc, nb_power);
|
||||
|
||||
%inline %{
|
||||
class ANumber {
|
||||
int num;
|
||||
public:
|
||||
ANumber(int d = 0) : num(d) {}
|
||||
ANumber __pow__(const ANumber &other, const ANumber *x) const {
|
||||
int val = (int)pow(num, other.num);
|
||||
val = x ? val % x->num : val;
|
||||
return ANumber(val);
|
||||
}
|
||||
int Value() const {
|
||||
return num;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue