Implement missing dotnet7 api
This commit is contained in:
@@ -180,10 +180,10 @@ namespace FlaxEngine
|
||||
};
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static void RegisterNativeLibrary(IntPtr moduleName_, IntPtr modulePath_)
|
||||
internal static void RegisterNativeLibrary(IntPtr moduleNamePtr, IntPtr modulePathPtr)
|
||||
{
|
||||
string moduleName = Marshal.PtrToStringAnsi(moduleName_);
|
||||
string modulePath = Marshal.PtrToStringAnsi(modulePath_);
|
||||
string moduleName = Marshal.PtrToStringAnsi(moduleNamePtr);
|
||||
string modulePath = Marshal.PtrToStringAnsi(modulePathPtr);
|
||||
nativeLibraryPaths[moduleName] = modulePath;
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static unsafe void GetManagedClasses(ManagedHandle assemblyHandle, NativeClassDefinitions** managedClasses, int* managedClassCount)
|
||||
internal static void GetManagedClasses(ManagedHandle assemblyHandle, NativeClassDefinitions** managedClasses, int* managedClassCount)
|
||||
{
|
||||
Assembly assembly = Unsafe.As<Assembly>(assemblyHandle.Target);
|
||||
var assemblyTypes = GetAssemblyTypes(assembly);
|
||||
@@ -233,7 +233,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static unsafe void GetManagedClassFromType(ManagedHandle typeHandle, NativeClassDefinitions* managedClass, ManagedHandle* assemblyHandle)
|
||||
internal static void GetManagedClassFromType(ManagedHandle typeHandle, NativeClassDefinitions* managedClass, ManagedHandle* assemblyHandle)
|
||||
{
|
||||
Type type = Unsafe.As<Type>(typeHandle.Target);
|
||||
*managedClass = new NativeClassDefinitions
|
||||
@@ -448,7 +448,6 @@ namespace FlaxEngine
|
||||
{
|
||||
MethodHolder methodHolder = Unsafe.As<MethodHolder>(methodHandle.Target);
|
||||
Type returnType = methodHolder.returnType;
|
||||
|
||||
return GetTypeGCHandle(returnType);
|
||||
}
|
||||
|
||||
@@ -515,7 +514,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static unsafe ManagedHandle GetArrayTypeFromElementType(ManagedHandle elementTypeHandle)
|
||||
internal static ManagedHandle GetArrayTypeFromElementType(ManagedHandle elementTypeHandle)
|
||||
{
|
||||
Type elementType = Unsafe.As<Type>(elementTypeHandle.Target);
|
||||
Type classType = elementType.MakeArrayType();
|
||||
@@ -523,7 +522,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static unsafe IntPtr GetArrayPointer(ManagedHandle arrayHandle)
|
||||
internal static IntPtr GetArrayPointer(ManagedHandle arrayHandle)
|
||||
{
|
||||
if (!arrayHandle.IsAllocated)
|
||||
return IntPtr.Zero;
|
||||
@@ -581,11 +580,43 @@ namespace FlaxEngine
|
||||
return GetTypeGCHandle(classType);
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static IntPtr GetObjectString(ManagedHandle handle)
|
||||
{
|
||||
object obj = handle.Target;
|
||||
string result = string.Empty;
|
||||
try
|
||||
{
|
||||
result = obj.ToString();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
return ManagedHandle.ToIntPtr(result);
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static int GetObjectHashCode(ManagedHandle handle)
|
||||
{
|
||||
object obj = handle.Target;
|
||||
int result = 0;
|
||||
try
|
||||
{
|
||||
result = obj.GetHashCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the address of the boxed value type.
|
||||
/// </summary>
|
||||
[UnmanagedCallersOnly]
|
||||
internal static unsafe IntPtr UnboxValue(ManagedHandle handle)
|
||||
internal static IntPtr UnboxValue(ManagedHandle handle)
|
||||
{
|
||||
object value = handle.Target;
|
||||
Type type = value.GetType();
|
||||
@@ -727,7 +758,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static ManagedHandle LoadAssemblyImage(IntPtr data, int len, IntPtr assemblyPath_, IntPtr* assemblyName, IntPtr* assemblyFullName)
|
||||
internal static ManagedHandle LoadAssemblyImage(IntPtr data, int len, IntPtr assemblyPathPtr, IntPtr* assemblyName, IntPtr* assemblyFullName)
|
||||
{
|
||||
if (!firstAssemblyLoaded)
|
||||
{
|
||||
@@ -740,7 +771,7 @@ namespace FlaxEngine
|
||||
return GetAssemblyHandle(flaxEngineAssembly);
|
||||
}
|
||||
|
||||
string assemblyPath = Marshal.PtrToStringAnsi(assemblyPath_);
|
||||
string assemblyPath = Marshal.PtrToStringAnsi(assemblyPathPtr);
|
||||
|
||||
byte[] raw = new byte[len];
|
||||
Marshal.Copy(data, raw, 0, len);
|
||||
@@ -772,9 +803,9 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static ManagedHandle GetAssemblyByName(IntPtr name_, IntPtr* assemblyName, IntPtr* assemblyFullName)
|
||||
internal static ManagedHandle GetAssemblyByName(IntPtr namePtr, IntPtr* assemblyName, IntPtr* assemblyFullName)
|
||||
{
|
||||
string name = Marshal.PtrToStringAnsi(name_);
|
||||
string name = Marshal.PtrToStringAnsi(namePtr);
|
||||
Assembly assembly = Utils.GetAssemblies().FirstOrDefault(x => x.GetName().Name == name);
|
||||
if (assembly == null)
|
||||
return new ManagedHandle();
|
||||
@@ -844,7 +875,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static unsafe int NativeSizeOf(ManagedHandle typeHandle)
|
||||
internal static int NativeSizeOf(ManagedHandle typeHandle)
|
||||
{
|
||||
Type type = Unsafe.As<Type>(typeHandle.Target);
|
||||
Type nativeType = GetInternalType(type) ?? type;
|
||||
@@ -930,6 +961,14 @@ namespace FlaxEngine
|
||||
return ManagedHandle.Alloc(exception, GCHandleType.Weak);
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static ManagedHandle GetException(IntPtr msgPtr)
|
||||
{
|
||||
string msg = Marshal.PtrToStringAnsi(msgPtr);
|
||||
var exception = new Exception(msg);
|
||||
return ManagedHandle.Alloc(exception, GCHandleType.Weak);
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static ManagedHandle GetNotSupportedException()
|
||||
{
|
||||
|
||||
@@ -326,19 +326,19 @@ MClass* MCore::Object::GetClass(MObject* obj)
|
||||
{
|
||||
static void* GetObjectTypePtr = GetStaticMethodPointer(TEXT("GetObjectType"));
|
||||
void* classHandle = CallStaticMethod<void*, void*>(GetObjectTypePtr, obj);
|
||||
return GetOrCreateClass((void*)classHandle);
|
||||
return GetOrCreateClass(classHandle);
|
||||
}
|
||||
|
||||
MString* MCore::Object::ToString(MObject* obj)
|
||||
{
|
||||
MISSING_CODE("TODO: MCore::Object::ToString"); // TODO: MCore::Object::ToString
|
||||
return nullptr;
|
||||
static void* GetObjectStringPtr = GetStaticMethodPointer(TEXT("GetObjectString"));
|
||||
return (MString*)CallStaticMethod<void*, void*>(GetObjectStringPtr, obj);
|
||||
}
|
||||
|
||||
int32 MCore::Object::GetHashCode(MObject* obj)
|
||||
{
|
||||
MISSING_CODE("TODO: MCore::Object::GetHashCode"); // TODO: MCore::Object::GetHashCode
|
||||
return 0;
|
||||
static void* GetObjectStringPtr = GetStaticMethodPointer(TEXT("GetObjectHashCode"));
|
||||
return CallStaticMethod<int32, void*>(GetObjectStringPtr, obj);
|
||||
}
|
||||
|
||||
MString* MCore::String::GetEmpty(MDomain* domain)
|
||||
@@ -490,7 +490,8 @@ MObject* MCore::Exception::GetNullReference()
|
||||
|
||||
MObject* MCore::Exception::Get(const char* msg)
|
||||
{
|
||||
return nullptr; // TODO: implement generic exception with custom message
|
||||
static void* GetExceptionPtr = GetStaticMethodPointer(TEXT("GetException"));
|
||||
return (MObject*)CallStaticMethod<void*, const char*>(GetExceptionPtr, msg);
|
||||
}
|
||||
|
||||
MObject* MCore::Exception::GetArgument(const char* arg, const char* msg)
|
||||
@@ -748,7 +749,7 @@ MClass::MClass(const MAssembly* parentAssembly, void* handle, const char* name,
|
||||
_isAbstract = !_isStatic && (attributes & MTypeAttributes::Abstract) == MTypeAttributes::Abstract;
|
||||
_isInterface = (attributes & MTypeAttributes::ClassSemanticsMask) == MTypeAttributes::Interface;
|
||||
|
||||
// TODO: pass type info from C# side at once (pack into flags)
|
||||
// TODO: pass type info from C# side at once (pack into flags with attributes)
|
||||
|
||||
static void* TypeIsValueTypePtr = GetStaticMethodPointer(TEXT("TypeIsValueType"));
|
||||
_isValueType = CallStaticMethod<bool, void*>(TypeIsValueTypePtr, handle);
|
||||
@@ -1484,7 +1485,7 @@ bool InitHostfxr(const String& configPath, const String& libraryPath)
|
||||
get_hostfxr_params.size = sizeof(hostfxr_initialize_parameters);
|
||||
get_hostfxr_params.assembly_path = library_path.Get();
|
||||
FLAX_CORECLR_STRING dotnetRoot;
|
||||
// TODO: implement proper lookup for dotnet instalation folder and handle standalone build of FlaxGame
|
||||
// TODO: implement proper lookup for dotnet installation folder and handle standalone build of FlaxGame
|
||||
#if PLATFORM_MAC
|
||||
get_hostfxr_params.dotnet_root = "/usr/local/share/dotnet";
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user