48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using PorygonSharp.EvalValues;
|
|
|
|
namespace PorygonSharp
|
|
{
|
|
internal struct EvaluateResult : IDisposable
|
|
{
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
private struct EvaluateResultInternal
|
|
{
|
|
public readonly IntPtr Value;
|
|
public readonly bool Result;
|
|
}
|
|
|
|
private readonly IntPtr _ptr;
|
|
private readonly EvaluateResultInternal _internal;
|
|
public EvaluateResult(IntPtr ptr)
|
|
{
|
|
_ptr = ptr;
|
|
_internal = Marshal.PtrToStructure<EvaluateResultInternal>(ptr);
|
|
}
|
|
|
|
public EvalValue GetValue()
|
|
{
|
|
return new EvalValue(_internal.Value);
|
|
}
|
|
|
|
public bool IsSuccess()
|
|
{
|
|
return !_internal.Result;
|
|
}
|
|
|
|
public string GetError()
|
|
{
|
|
return GetErrorMessage(_ptr);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Marshal.FreeHGlobal(_ptr);
|
|
}
|
|
|
|
[DllImport("libPorygonLang", EntryPoint = "GetResultError", CallingConvention = CallingConvention.Cdecl)]
|
|
private static extern string GetErrorMessage(IntPtr ptr);
|
|
|
|
}
|
|
} |