3
3
using System . Collections . Generic ;
4
4
using System . Linq ;
5
5
using System . Runtime . InteropServices ;
6
+ using System . IO ;
6
7
7
8
//Written by Johnathan Bizzano
8
9
namespace JuliaInterface
@@ -15,10 +16,11 @@ public class Julia
15
16
16
17
public static void Init ( )
17
18
{
19
+ var os = OperatingEnvironment . GetEnvironment ( ) ;
18
20
var proc = new Process {
19
21
StartInfo = new ProcessStartInfo {
20
- FileName = "where.exe" ,
21
- Arguments = "Julia " ,
22
+ FileName = os . GetWhereExe ( ) ,
23
+ Arguments = "julia " ,
22
24
UseShellExecute = false ,
23
25
RedirectStandardOutput = true ,
24
26
CreateNoWindow = true
@@ -28,25 +30,26 @@ public static void Init()
28
30
while ( ! proc . StandardOutput . EndOfStream )
29
31
{
30
32
string location = proc . StandardOutput . ReadLine ( ) ;
31
- if ( location . Contains ( "julia.exe" ) ) {
32
- Init ( location . Substring ( 1 , location . Length - 11 ) ) ;
33
+ if ( location . Contains ( "julia" ) ) {
34
+ location = os . TrimJuliaPath ( location ) ;
35
+ Init ( location ) ;
33
36
return ;
34
- }
35
-
37
+ }
36
38
}
37
39
throw new Exception ( "Julia Path Not Found" ) ;
38
40
}
39
41
40
-
41
42
42
43
public static void Init ( string dir ) {
43
- JuliaCalls . SetDllDirectory ( dir ) ;
44
+ var env = Environment . CurrentDirectory ;
45
+ Environment . CurrentDirectory = dir ;
44
46
JuliaCalls . jl_init ( ) ;
45
47
JuliaCalls . jl_eval_string ( System . Text . Encoding . UTF8 . GetString ( Resource1 . JuliaInterface ) ) ;
46
48
JLModule . init_mods ( ) ;
47
49
JLType . init_types ( ) ;
48
50
JLFun . init_funs ( ) ;
49
51
NativeSharp . init ( ) ;
52
+ Environment . CurrentDirectory = env ;
50
53
}
51
54
52
55
public static void SetGlobal ( JLModule m , JLSym sym , JLVal val )
@@ -68,6 +71,7 @@ public static void CheckExceptions(){
68
71
}
69
72
70
73
public static void Exit ( int code ) => JuliaCalls . jl_atexit_hook ( code ) ;
74
+
71
75
public static JLVal Eval ( string str ) {
72
76
var val = JuliaCalls . jl_eval_string ( str ) ;
73
77
CheckExceptions ( ) ;
0 commit comments