Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
HyperSphereStudio committed Jan 11, 2022
1 parent 6cf5c68 commit ca88823
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
20 changes: 12 additions & 8 deletions src/csharp/Julia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.IO;

//Written by Johnathan Bizzano
namespace JuliaInterface
Expand All @@ -15,10 +16,11 @@ public class Julia

public static void Init()
{
var os = OperatingEnvironment.GetEnvironment();
var proc = new Process {
StartInfo = new ProcessStartInfo {
FileName = "where.exe",
Arguments = "Julia",
FileName = os.GetWhereExe(),
Arguments = "julia",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
Expand All @@ -28,25 +30,26 @@ public static void Init()
while (!proc.StandardOutput.EndOfStream)
{
string location = proc.StandardOutput.ReadLine();
if (location.Contains("julia.exe")){
Init(location.Substring(1, location.Length - 11));
if (location.Contains("julia")){
location = os.TrimJuliaPath(location);
Init(location);
return;
}

}
}
throw new Exception("Julia Path Not Found");
}



public static void Init(string dir){
JuliaCalls.SetDllDirectory(dir);
var env = Environment.CurrentDirectory;
Environment.CurrentDirectory = dir;
JuliaCalls.jl_init();
JuliaCalls.jl_eval_string(System.Text.Encoding.UTF8.GetString(Resource1.JuliaInterface));
JLModule.init_mods();
JLType.init_types();
JLFun.init_funs();
NativeSharp.init();
Environment.CurrentDirectory = env;
}

public static void SetGlobal(JLModule m, JLSym sym, JLVal val)
Expand All @@ -68,6 +71,7 @@ public static void CheckExceptions(){
}

public static void Exit(int code) => JuliaCalls.jl_atexit_hook(code);

public static JLVal Eval(string str){
var val = JuliaCalls.jl_eval_string(str);
CheckExceptions();
Expand Down
4 changes: 0 additions & 4 deletions src/csharp/JuliaCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ namespace JuliaInterface
public class JuliaCalls
{


[DllImport("kernel32.dll")]
public static extern bool SetDllDirectory(string path);


public enum JLIMAGESEARCH{
JL_IMAGE_CWD = 0,
Expand Down
43 changes: 43 additions & 0 deletions src/csharp/OperatingEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace JuliaInterface
{
public abstract class OperatingEnvironment
{

public OperatingEnvironment() { }

public abstract string GetWhereExe();
public abstract string TrimJuliaPath(string s);

public static OperatingEnvironment GetEnvironment(){
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return new WindowsEnvironment();
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return new LinuxEnvironment();
else throw new Exception("Unsupported Operating System!");
}
}

public class WindowsEnvironment : OperatingEnvironment
{

public override string GetWhereExe() => "where.exe";

public override string TrimJuliaPath(string s) => s.Substring(0, s.Length - 10);
}

public class LinuxEnvironment : OperatingEnvironment
{
public override string GetWhereExe() => "which";

public override string TrimJuliaPath(string s) => s;
}


}

0 comments on commit ca88823

Please sign in to comment.