diff --git a/PorygonSharp/EvalValues/DelegateEvalValue.cs b/PorygonSharp/EvalValues/DelegateEvalValue.cs index f1f3d27..ae25621 100644 --- a/PorygonSharp/EvalValues/DelegateEvalValue.cs +++ b/PorygonSharp/EvalValues/DelegateEvalValue.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Runtime.InteropServices; +using PorygonSharp.UserData; using PorygonSharp.Utilities; namespace PorygonSharp.EvalValues @@ -32,8 +33,15 @@ namespace PorygonSharp.EvalValues parameters[i] = Caster.Cast(val, parametersTypes[i]); } - var result = _delegate.DynamicInvoke(parameters); - return EvalValueCreator.CreateValue(result).GetPointer(); + try + { + var result = _delegate.DynamicInvoke(parameters); + return new UserDataReturnValue(EvalValueCreator.CreateValue(result)).GetPointer(); + } + catch (Exception e) + { + return new UserDataReturnValue(e.ToString()).GetPointer(); + } } } } \ No newline at end of file diff --git a/PorygonSharp/EvalValues/EvalValue.cs b/PorygonSharp/EvalValues/EvalValue.cs index c1ee037..03c4873 100644 --- a/PorygonSharp/EvalValues/EvalValue.cs +++ b/PorygonSharp/EvalValues/EvalValue.cs @@ -105,7 +105,7 @@ namespace PorygonSharp.EvalValues return Handle; } - public bool IsNumericValueFloat() + private bool IsNumericValueFloat() { return IsNumericValueFloat(Handle) == 1; } diff --git a/PorygonSharp/UserData/UserDataFunctionField.cs b/PorygonSharp/UserData/UserDataFunctionField.cs index 9261294..3b73a9b 100644 --- a/PorygonSharp/UserData/UserDataFunctionField.cs +++ b/PorygonSharp/UserData/UserDataFunctionField.cs @@ -42,8 +42,15 @@ namespace PorygonSharp.UserData } var parentObj = GCHandle.FromIntPtr(parent).Target; - var result = method.Invoke(parentObj, evaluatedParameters); - return EvalValueCreator.CreateValue(result).GetPointer(); + try + { + var result = method.Invoke(parentObj, evaluatedParameters); + return new UserDataReturnValue(EvalValueCreator.CreateValue(result)).GetPointer(); + } + catch (Exception e) + { + return new UserDataReturnValue(e.ToString()).GetPointer(); + } }; } diff --git a/PorygonSharp/UserData/UserDataReturnValue.cs b/PorygonSharp/UserData/UserDataReturnValue.cs new file mode 100644 index 0000000..66f6ca4 --- /dev/null +++ b/PorygonSharp/UserData/UserDataReturnValue.cs @@ -0,0 +1,35 @@ +using System; +using System.Runtime.InteropServices; +using PorygonSharp.EvalValues; + +namespace PorygonSharp.UserData +{ + internal class UserDataReturnValue + { + private readonly IntPtr _ptr; + public UserDataReturnValue(EvalValue value) + { + _ptr = ReturnValue(value.GetPointer()); + } + + public UserDataReturnValue(string message) + { + _ptr = ErrorValue(message); + } + public static implicit operator UserDataReturnValue(EvalValue val) + { + return new UserDataReturnValue(val); + } + + internal IntPtr GetPointer() + { + return _ptr; + } + + [DllImport("PorygonLang", EntryPoint = "ReturnValue", CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr ReturnValue(IntPtr value); + + [DllImport("PorygonLang", EntryPoint = "ErrorValue", CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr ErrorValue(string message); + } +} \ No newline at end of file diff --git a/PorygonSharp/libPorygonLang.so b/PorygonSharp/libPorygonLang.so index 028ab9a..bdfaaa4 100755 Binary files a/PorygonSharp/libPorygonLang.so and b/PorygonSharp/libPorygonLang.so differ diff --git a/PorygonSharpTests/PorygonSharpTests.csproj b/PorygonSharpTests/PorygonSharpTests.csproj index 10f4136..5aabcc6 100644 --- a/PorygonSharpTests/PorygonSharpTests.csproj +++ b/PorygonSharpTests/PorygonSharpTests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + netcoreapp3.0 false