33 lines
954 B
C#
33 lines
954 B
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace PorygonSharp
|
|
{
|
|
internal static class CoreSetup
|
|
{
|
|
public static Action<string> Print = Console.WriteLine;
|
|
|
|
private delegate void InternalPrintDelegate(IntPtr ptr);
|
|
private static readonly InternalPrintDelegate InternalPrint = PrintFunc;
|
|
|
|
static CoreSetup()
|
|
{
|
|
SetPrintFunc();
|
|
}
|
|
|
|
private static void SetPrintFunc()
|
|
{
|
|
var funcPtr = Marshal.GetFunctionPointerForDelegate(InternalPrint);
|
|
InternalSetPrintFunc(funcPtr);
|
|
}
|
|
|
|
private static void PrintFunc(IntPtr ptr)
|
|
{
|
|
var message = Marshal.PtrToStringUni(ptr);
|
|
Print(message);
|
|
}
|
|
|
|
[DllImport("libPorygonLang", EntryPoint = "SetDefaultPrintFunc", CallingConvention = CallingConvention.Cdecl)]
|
|
private static extern double InternalSetPrintFunc(IntPtr ptr);
|
|
}
|
|
} |