mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Start CoreClr from Beef and basic interaction
This commit is contained in:
+5
-3
@@ -1,4 +1,5 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace GlitchyEngine;
|
||||
|
||||
@@ -44,7 +45,8 @@ public class Log
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Critical, message);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
public static extern string LogMessage_Impl(LogLevel logLevel, string message);
|
||||
|
||||
//[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
[DllImport("GlitchyEditor.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Log::LogMessage_Impl")]
|
||||
public static extern void LogMessage_Impl(LogLevel logLevel, string message);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<BaseOutputPath></BaseOutputPath>
|
||||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
||||
|
||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<Nullable>enable</Nullable>
|
||||
<!--<DebugType>embedded</DebugType>-->
|
||||
<!--<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>-->
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="PowerShell ./postbuild.ps1 -sourceDir $(OutDir) -destinationDir "..\GlitchyEditor\resources\scripts"" />
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Half" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ScriptCoreGenerator\ScriptCoreGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Security;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Loader;
|
||||
using GlitchyEngine.Core;
|
||||
using GlitchyEngine.Math;
|
||||
|
||||
@@ -74,5 +80,49 @@ internal static class ScriptGlue
|
||||
internal static extern float4 modf_float4(float4 x, out float4 integerPart);
|
||||
|
||||
#endregion
|
||||
|
||||
private static AssemblyLoadContext? _scriptAssemblyContext;
|
||||
|
||||
private static Assembly? _appAssembly;
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static unsafe void LoadScriptAssembly(byte* assemblyData, long assemblyLength, byte* pdbData, long pdbLength)
|
||||
{
|
||||
using UnmanagedMemoryStream assemblyStream = new(assemblyData, assemblyLength);
|
||||
|
||||
using UnmanagedMemoryStream? pdbStream = (pdbData != null) ? new UnmanagedMemoryStream(pdbData, pdbLength) : null;
|
||||
|
||||
LoadAssembly(assemblyStream, pdbStream);
|
||||
}
|
||||
|
||||
private static void LoadAssembly(Stream assemblyStream, Stream? pdbStream)//(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
_scriptAssemblyContext ??= new AssemblyLoadContext("ScriptContext", true);
|
||||
|
||||
_appAssembly = _scriptAssemblyContext.LoadFromStream(assemblyStream, pdbStream);
|
||||
|
||||
Debug.Assert(_appAssembly != null);
|
||||
|
||||
// Test the loaded assembly
|
||||
_appAssembly.GetType("Sandbox.TestClass")?.GetMethod("InternalTest")?.Invoke(null, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Fehler: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static void UnloadAssemblies()
|
||||
{
|
||||
UnloadContext();
|
||||
}
|
||||
|
||||
private static void UnloadContext()
|
||||
{
|
||||
_scriptAssemblyContext?.Unload();
|
||||
_scriptAssemblyContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user