Adds support for Python __r*__ operators (by Karl Wette)

The Python operator model, when evaluating e.g. x + y, is to call
x.__add__(y), then y.__radd__(x) if the former does not exist, etc.
This patch adds similar functionality to the SWIG runtime code.
For the special case of the comparison operators __l*__ and __g*__,
the reverse operators are __g*__ and __l*__ respectively.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12674 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Xavier Delacour 2011-05-17 02:00:25 +00:00
commit 2d5c4302b0

View file

@ -809,6 +809,16 @@ namespace Swig {
octave_value ret;
if (lhs_ost && lhs_ost->dispatch_binary_op(std::string("__") + op_name + std::string("__"), rhs, ret))
return ret;
if (rhs_ost) {
if (strlen(op_name) == 2 && (op_name[1] == 't' || op_name[1] == 'e')) {
if (op_name[0] == 'l' && rhs_ost->dispatch_binary_op(std::string("__g") + op_name[1] + std::string("__"), lhs, ret))
return ret;
if (op_name[0] == 'g' && rhs_ost->dispatch_binary_op(std::string("__l") + op_name[1] + std::string("__"), lhs, ret))
return ret;
}
if (rhs_ost->dispatch_binary_op(std::string("__r") + op_name + std::string("__"), lhs, ret))
return ret;
}
std::string symbol;
octave_value_list args;