juliamatlab / mexjulia

embedding Julia in the MATLAB process.
MIT License
52 stars 14 forks source link

jl.include() breaks with called from scripts outside the target directory #54

Closed sg-s closed 5 years ago

sg-s commented 7 years ago

this doesn't work:

location of Julia code: "/code/A/test.jl" location of MATLAB script: "/code/B.foo.m" content of foo.m:

jl.include("/code/A/test.jl")

even though this works:

>>> jl.include("/code/A/test.jl")

and foo.m works if I move it to /code/A/

sg-s commented 7 years ago

solution: replace the mexn static method with this:

        function varargout = mexn(nout, fn, varargin)
            jl.check_initialized;
            outputs = cell(nout+1, 1);
            try
                [outputs{:}] = mexjulia('jl_mex', fn, varargin{:});
                varargout = outputs(2:end);
                result = outputs{1};
                if ~islogical(result)
                    throw(result);
                end
            catch
                varargout{1} = [];
            end
        end

I don't know why this works, but it does.