using System;
using System.Runtime.InteropServices;

namespace PkmnLibSharp.Utilities
{
    public static class SignalHandler
    {
        public delegate void SignalDelegate(string s);
        private delegate void InternalSignalDelegate(IntPtr ptr);

        private static InternalSignalDelegate? _internalSignalDelegate;

        public static void SetSignalListener(SignalDelegate del)
        {
            _internalSignalDelegate = ptr =>
            {
                del(ptr.PtrString()!);
            };
            Arbutils.Generated.C.SetSignalCallback(Marshal.GetFunctionPointerForDelegate(_internalSignalDelegate));
        }
    }
}