Files
LuaCsForBarotraumaEP/Libraries/MonoGame.Framework/Src/MonoGame.Framework/Utilities/FuncLoader.iOS.cs
2019-06-25 16:00:44 +03:00

34 lines
952 B
C#

using System;
using System.Runtime.InteropServices;
using ObjCRuntime;
namespace MonoGame.Utilities
{
internal class FuncLoader
{
public static IntPtr LoadLibrary(string libname)
{
return Dlfcn.dlopen(libname, 0);
}
public static T LoadFunction<T>(IntPtr library, string function, bool throwIfNotFound = false)
{
var ret = Dlfcn.dlsym(library, function);
if (ret == IntPtr.Zero)
{
if (throwIfNotFound)
throw new EntryPointNotFoundException(function);
return default(T);
}
// TODO: Use the function bellow once Protobuild gets axed
// requires .NET Framework 4.5.1 and its useful for corert
// return Marshal.GetDelegateForFunctionPointer<T>(ret);
return (T)(object)Marshal.GetDelegateForFunctionPointer(ret, typeof(T));
}
}
}