Skip to content

Commit ccd616d

Browse files
committed
2 parents 767af06 + f5bc892 commit ccd616d

File tree

6 files changed

+51
-26
lines changed

6 files changed

+51
-26
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,26 @@ xx, yy = mxcall(:meshgrid, 2, x, y)
311311

312312
``mxcall`` puts the input arguments to the MATLAB workspace (using mangled names), evaluates the function call in MATLAB, and retrievs the variable from the MATLAB session. This function is mainly provided for convenience. However, you should keep in mind that it may incur considerable overhead due to the communication between MATLAB and Julia domain.
313313

314-
#### Viewing the MATLAB Session
314+
#### Viewing the MATLAB Session (Windows only)
315315

316-
To open an interactive window for the MATLAB session, use the command `show_msession()`. To hide the window, use `hide_msession()`. Note that closing this window will result in an error, so it is advised that one uses the `hide_msession()` command instead.
316+
To open an interactive window for the MATLAB session, use the command `show_msession()` and to hide the window, use `hide_msession()`. *Warning: manually closing this window will result in an error or result in a segfault; it is advised that you only use the `hide_msession()` command to hide the interactive window.*
317317

318318
Note that this feature only works on Windows.
319319

320+
```julia
321+
# default
322+
show_msession() # open the default MATLAB session interactive window
323+
get_msession_visiblity() # get the session's visibility state
324+
hide_msession() # hide the default MATLAB session interactive window
325+
326+
# similarily
327+
s = MSession()
328+
show_msession(s)
329+
get_msession_visiblity(a)
330+
hide_msession(s)
331+
```
332+
333+
320334
#### Advanced use of MATLAB Engines
321335

322336
This package provides a series of functions for users to control the communication with MATLAB sessions.

src/MATLAB.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ export MSession, MatFile,
3131
eval_string, get_mvariable, get_variable, put_variable, put_variables,
3232
variable_names, read_matfile, write_matfile,
3333
mxcall,
34-
@mput, @mget, @matlab, @mat_str,
35-
show_msession, hide_msession
34+
@mput, @mget, @matlab, @mat_str
3635

36+
if is_windows()
37+
export show_msession, hide_msession, get_msession_visiblity
38+
end
3739

3840
# exceptions
3941
type MEngineError <: Exception
@@ -65,6 +67,7 @@ function __init__()
6567
eng_open[] = engfunc(:engOpen)
6668
eng_close[] = engfunc(:engClose)
6769
eng_set_visible[] = engfunc(:engSetVisible)
70+
eng_get_visible[] = engfunc(:engGetVisible)
6871
eng_output_buffer[] = engfunc(:engOutputBuffer)
6972
eng_eval_string[] = engfunc(:engEvalString)
7073
eng_put_variable[] = engfunc(:engPutVariable)

src/engine.jl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,25 @@ function close_default_msession()
9090
return nothing
9191
end
9292

93-
function show_msession(m::MSession = get_default_msession())
94-
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 1)
95-
ret != 0 && throw(MEngineError("failed to show MATLAB engine session (err = $ret)"))
96-
return nothing
97-
end
93+
if is_windows()
94+
function show_msession(m::MSession = get_default_msession())
95+
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 1)
96+
ret != 0 && throw(MEngineError("failed to show MATLAB engine session (err = $ret)"))
97+
return nothing
98+
end
9899

99-
function hide_msession(m::MSession = get_default_msession())
100-
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 0)
101-
ret != 0 && throw(MEngineError("failed to hide MATLAB engine session (err = $ret)"))
102-
return nothing
103-
end
100+
function hide_msession(m::MSession = get_default_msession())
101+
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 0)
102+
ret != 0 && throw(MEngineError("failed to hide MATLAB engine session (err = $ret)"))
103+
return nothing
104+
end
104105

106+
function get_msession_visiblity(m::MSession = get_default_msession())
107+
vis = Ref{Cint}(true)
108+
ccall(eng_get_visible[], Int, (Ptr{Void}, Ptr{Cint}), m, vis)
109+
return vis[] == 1 ? true : false
110+
end
111+
end
105112

106113
###########################################################
107114
#

src/init.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const libmat = Ref{Ptr{Void}}()
99
const eng_open = Ref{Ptr{Void}}()
1010
const eng_close = Ref{Ptr{Void}}()
1111
const eng_set_visible = Ref{Ptr{Void}}()
12+
const eng_get_visible = Ref{Ptr{Void}}()
1213
const eng_output_buffer = Ref{Ptr{Void}}()
1314
const eng_eval_string = Ref{Ptr{Void}}()
1415
const eng_put_variable = Ref{Ptr{Void}}()
@@ -84,7 +85,7 @@ const mx_set_field = Ref{Ptr{Void}}()
8485
const mx_get_field_bynum = Ref{Ptr{Void}}()
8586
const mx_get_fieldname = Ref{Ptr{Void}}()
8687

87-
const mx_get_string = Ref{Ptr{Void}}(0)
88+
const mx_get_string = Ref{Ptr{Void}}()
8889

8990
# load I/O mat functions
9091

src/mxarray.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ function unsafe_convert(::Type{Ptr{Void}}, mx::MxArray)
4848
end
4949
# functions to create mxArray from Julia values/arrays
5050

51-
typealias MxRealNum Union{Float64,Float32,Int32,UInt32,Int64,UInt64,Int16,UInt16,Int8,UInt8,Bool}
52-
typealias MxComplexNum Union{Complex64, Complex128}
53-
typealias MxNum Union{MxRealNum, MxComplexNum}
51+
const MxRealNum = Union{Float64, Float32, Int32, UInt32, Int64, UInt64, Int16, UInt16, Int8, UInt8, Bool}
52+
const MxComplexNum = Union{Complex64, Complex128}
53+
const MxNum = Union{MxRealNum, MxComplexNum}
5454

5555
###########################################################
5656
#
5757
# MATLAB types
5858
#
5959
###########################################################
6060

61-
typealias mwSize UInt
62-
typealias mwIndex Int
63-
typealias mxClassID Cint
64-
typealias mxComplexity Cint
61+
const mwSize = UInt
62+
const mwIndex = Int
63+
const mxClassID = Cint
64+
const mxComplexity = Cint
6565

6666
const mxUNKNOWN_CLASS = convert(mxClassID, 0)
6767
const mxCELL_CLASS = convert(mxClassID, 1)
@@ -432,7 +432,7 @@ function get_fieldname(mx::MxArray, i::Integer)
432432
unsafe_string(p)
433433
end
434434

435-
typealias Pairs Union{Pair,NTuple{2}}
435+
const Pairs = Union{Pair, NTuple{2}}
436436

437437
function mxstruct(pairs::Pairs...)
438438
nf = length(pairs)

src/mxbase.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ function matlab_home_path()
1010
default_dir = "/Applications"
1111
if isdir(default_dir)
1212
dirs = readdir(default_dir)
13-
filter!(app -> ismatch(r"^MATLAB_R[0-9]+[ab]\.app$", dirs), dirs)
14-
if ~isempty(dirs)
13+
filter!(app -> ismatch(r"^MATLAB_R[0-9]+[ab]\.app$", app), dirs)
14+
if !isempty(dirs)
1515
matlab_home = joinpath(default_dir, maximum(dirs))
1616
end
1717
end
@@ -20,7 +20,7 @@ function matlab_home_path()
2020
if isdir(default_dir)
2121
dirs = readdir(default_dir)
2222
filter!(dir -> ismatch(r"^R[0-9]+[ab]$", dir), dirs)
23-
if ~isempty(dirs)
23+
if !isempty(dirs)
2424
matlab_home = joinpath(default_dir, maximum(dirs))
2525
end
2626
end

0 commit comments

Comments
 (0)