Skip to content

Commit 7f1189c

Browse files
committed
Initialize remaining Refs
1 parent 4e9b244 commit 7f1189c

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

src/MATLAB.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ function __init__()
5858
libmat[] = Libdl.dlopen(joinpath(lib_path, "libmat"), Libdl.RTLD_GLOBAL)
5959
libeng[] = Libdl.dlopen(joinpath(lib_path, "libeng"), Libdl.RTLD_GLOBAL)
6060

61-
# mxarray function
61+
# engine functions
62+
63+
eng_open[] = engfunc(:engOpen)
64+
eng_close[] = engfunc(:engClose)
65+
eng_set_visible[] = engfunc(:engSetVisible)
66+
eng_output_buffer[] = engfunc(:engOutputBuffer)
67+
eng_eval_string[] = engfunc(:engEvalString)
68+
eng_put_variable[] = engfunc(:engPutVariable)
69+
eng_get_variable[] = engfunc(:engGetVariable)
70+
71+
# mxarray functions
6272

6373
mx_destroy_array[] = mxfunc(:mxDestroyArray)
6474
mx_duplicate_array[] = mxfunc(:mxDuplicateArray)

src/engine.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ type MSession
1616
bufptr::Ptr{UInt8}
1717

1818
function MSession(bufsize::Integer = default_output_buffer_size)
19-
ep = ccall(engfunc(:engOpen), Ptr{Void}, (Ptr{UInt8},), default_startcmd)
19+
ep = ccall(eng_open[], Ptr{Void}, (Ptr{UInt8},), default_startcmd)
2020
ep == C_NULL && throw(MEngineError("failed to open a MATLAB engine session"))
2121
# hide the MATLAB command window on Windows
22-
is_windows() && ccall(engfunc(:engSetVisible ), Cint, (Ptr{Void}, Cint), ep, 0)
22+
is_windows() && ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), ep, 0)
2323

2424
buf = Array(UInt8, bufsize)
2525
if bufsize > 0
2626
bufptr = pointer(buf)
27-
ccall(engfunc(:engOutputBuffer), Cint, (Ptr{Void}, Ptr{UInt8}, Cint),
27+
ccall(eng_output_buffer[], Cint, (Ptr{Void}, Ptr{UInt8}, Cint),
2828
ep, bufptr, bufsize)
2929
else
3030
bufptr = convert(Ptr{UInt8}, C_NULL)
@@ -45,15 +45,15 @@ end
4545
function release(session::MSession)
4646
ptr = session.ptr
4747
if ptr != C_NULL
48-
ccall(engfunc(:engClose), Cint, (Ptr{Void},), ptr)
48+
ccall(eng_close[], Cint, (Ptr{Void},), ptr)
4949
end
5050
session.ptr = C_NULL
5151
return nothing
5252
end
5353

5454
function close(session::MSession)
5555
# close a MATLAB Engine session
56-
ret = ccall(engfunc(:engClose), Cint, (Ptr{Void},), session)
56+
ret = ccall(eng_close[], Cint, (Ptr{Void},), session)
5757
ret != 0 && throw(MEngineError("failed to close a MATLAB engine session (err = $ret)"))
5858
session.ptr = C_NULL
5959
return nothing
@@ -91,13 +91,13 @@ function close_default_msession()
9191
end
9292

9393
function show_msession(m::MSession = get_default_msession())
94-
ret = ccall(engfunc(:engSetVisible), Cint, (Ptr{Void}, Cint), m, 1)
94+
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 1)
9595
ret != 0 && throw(MEngineError("failed to show MATLAB engine session (err = $ret)"))
9696
return nothing
9797
end
9898

9999
function hide_msession(m::MSession = get_default_msession())
100-
ret = ccall(engfunc(:engSetVisible), Cint, (Ptr{Void}, Cint), m, 0)
100+
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 0)
101101
ret != 0 && throw(MEngineError("failed to hide MATLAB engine session (err = $ret)"))
102102
return nothing
103103
end
@@ -111,7 +111,7 @@ end
111111

112112
function eval_string(session::MSession, stmt::String)
113113
# evaluate a MATLAB statement in a given MATLAB session
114-
ret = ccall(engfunc(:engEvalString), Cint, (Ptr{Void}, Ptr{UInt8}), session, stmt)
114+
ret = ccall(eng_eval_string[], Cint, (Ptr{Void}, Ptr{UInt8}), session, stmt)
115115
ret != 0 && throw(MEngineError("invalid engine session (err = $ret)"))
116116

117117
bufptr = session.bufptr
@@ -129,7 +129,7 @@ eval_string(stmt::String) = eval_string(get_default_msession(), stmt)
129129

130130
function put_variable(session::MSession, name::Symbol, v::MxArray)
131131
# put a variable into a MATLAB engine session
132-
ret = ccall(engfunc(:engPutVariable), Cint, (Ptr{Void}, Ptr{UInt8}, Ptr{Void}), session, string(name), v)
132+
ret = ccall(eng_put_variable[], Cint, (Ptr{Void}, Ptr{UInt8}, Ptr{Void}), session, string(name), v)
133133
ret != 0 && throw(MEngineError("failed to put the variable $(name) into a MATLAB session (err = $ret)"))
134134
return nothing
135135
end
@@ -140,7 +140,7 @@ put_variable(name::Symbol, v) = put_variable(get_default_msession(), name, v)
140140

141141

142142
function get_mvariable(session::MSession, name::Symbol)
143-
pv = ccall(engfunc(:engGetVariable), Ptr{Void}, (Ptr{Void}, Ptr{UInt8}), session, string(name))
143+
pv = ccall(eng_get_variable[], Ptr{Void}, (Ptr{Void}, Ptr{UInt8}), session, string(name))
144144
pv == C_NULL && throw(MEngineError("failed to get the variable $(name) from a MATLAB session"))
145145
return MxArray(pv)
146146
end

src/init.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ const libeng = Ref{Ptr{Void}}()
44
const libmx = Ref{Ptr{Void}}()
55
const libmat = Ref{Ptr{Void}}()
66

7-
# mxarray function
7+
# matlab engine functions
8+
9+
const eng_open = Ref{Ptr{Void}}()
10+
const eng_close = Ref{Ptr{Void}}()
11+
const eng_set_visible = Ref{Ptr{Void}}()
12+
const eng_output_buffer = Ref{Ptr{Void}}()
13+
const eng_eval_string = Ref{Ptr{Void}}()
14+
const eng_put_variable = Ref{Ptr{Void}}()
15+
const eng_get_variable = Ref{Ptr{Void}}()
16+
17+
# mxarray functions
818

919
const mx_destroy_array = Ref{Ptr{Void}}()
1020
const mx_duplicate_array = Ref{Ptr{Void}}()

0 commit comments

Comments
 (0)