Thanks @jondeuce !
Yes, I was looking for some time into this and came to about the same conclusions: command-line (non-API) and MAT.jl. My code uses Java-streams and a simple julia -iq call, not requiring DaemonMode.jl.
This is one of my very first Julia codes, so no bells and whistles as your implementation.
Also, my call pattern is a bit different,
jl.call('[a, m] = addmult', 2, 3);
a+m
ans =
11
I am curious to see how your matlabify type translation and other features chime in.
jlcall.jl
#=
jlcall.jl
Matlab-Julia interface, called from jlcall.m
=#
using MAT
function jlcall(iofile)
# read call arguments from iofile
matvars = matread(iofile)
outvars = matvars["outvars"]
fun = matvars["fun"]
sfun = Symbol(fun)
inputs = matvars["varargin"]
# if necessary, load function, run Julia
if true #!(@isdefined sfun)
funfile = matvars["fun"] * ".jl"
println("...loading $funfile")
include(funfile)
end
results = @eval $sfun($inputs...)
# save output arguments to iofile
d = Dict{String, Any}()
for i = 1:length(outvars)
d[outvars[i]] = results[i]
end
matwrite(iofile, d)
println("OK")
end
jlcall.m
function jlcall(outvars_fun, varargin)
%JLCALL Execute Julia function from Matlab
% jlcall('[outvar1, outvar2, ...] = fun', var1, var2, ...)
% fun is a Julia function, built-in or defined in <fun>.jl
%
% Example:
%
% >> jlcall('[a, m] = addmult', 2, 3)
% >> a+m
% ans =
% 11
outvars_fun = split(outvars_fun, {'[',']','=',',',' '});
outvars_fun(cellfun('isempty',outvars_fun)) = [];
outvars = outvars_fun(1:end-1);
fun = outvars_fun{end};
iofile = [tempname, '.mat'];
save(iofile, 'outvars', 'fun', 'varargin');
system(sprintf('julia jlcall.jl %s', strrep(iofile, '\', '/')));
load(iofile, outvars{:});
system(sprintf('rm %s', iofile));
end