bastibe / transplant

Transplant is an easy way of calling Matlab from Python
https://transplant.readthedocs.io
Other
110 stars 26 forks source link

Nargout for class methods #50

Open tsdev opened 7 years ago

tsdev commented 7 years ago

08478bbe8ab42777ff0cc7b893cda29ab6f05212: This fails when a class method name is identical to a function on the MATLAB search path. For example calling the method myclass.plot(), nargout will return the number of arguments of the MATLAB built-in plot function. That's why I added a bit more checking:

try
    [~, funType] = which(msg('name'));
    funType = strsplit(funType,' ');
    if numel(funType)==2 && strcmp(funType{2},'method')
        argTemp = msg('args');
        className = funType{1};
        if ~isempty(argTemp) && isa(argTemp{1},className)
            % the function name corresponds to the
            % class of the first argument
            resultsize = nargout(msg('name'));
        end
    end

    if isempty(resultsize)
        resultsize = nargout(fun);
    end
catch
    resultsize = -1;
end
bastibe commented 7 years ago

Right now, I don't have enough time to look into this. I'd be grateful for a pull request. Otherwise, I'll have a look in two weeks.