mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Now passing strings between c++ -> c# -> c++
This commit is contained in:
@@ -64,7 +64,7 @@ namespace Nuake
|
||||
float DOFGain = 100.f;
|
||||
float DOFBias = 0.0f;
|
||||
float DOFFringe = 0.0f;
|
||||
float DOFNAmmount = 0.0001;
|
||||
float DOFNAmmount = 0.0001f;
|
||||
float DOFDbSize = 1.25f;
|
||||
float DOFFeather = 1.0f;
|
||||
|
||||
|
||||
@@ -18,6 +18,26 @@ void ExceptionCallback(std::string_view InMessage)
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
ScriptingEngineNet::ScriptingEngineNet()
|
||||
{
|
||||
auto coralDir = "";
|
||||
Coral::HostSettings settings =
|
||||
{
|
||||
.CoralDirectory = coralDir,
|
||||
.ExceptionCallback = ExceptionCallback
|
||||
};
|
||||
m_HostInstance = CreateScope<Coral::HostInstance>();
|
||||
m_HostInstance->Initialize(settings);
|
||||
|
||||
m_LoadContext = CreateScope<Coral::AssemblyLoadContext>(m_HostInstance->CreateAssemblyLoadContext("NuakeEngineContext"));
|
||||
}
|
||||
|
||||
ScriptingEngineNet::~ScriptingEngineNet()
|
||||
{
|
||||
m_HostInstance->UnloadAssemblyLoadContext(*m_LoadContext);
|
||||
m_HostInstance->Shutdown();
|
||||
}
|
||||
|
||||
ScriptingEngineNet& ScriptingEngineNet::Get()
|
||||
{
|
||||
static ScriptingEngineNet instance;
|
||||
@@ -31,23 +51,19 @@ namespace Nuake
|
||||
|
||||
void ScriptingEngineNet::Initialize()
|
||||
{
|
||||
auto coralDir = "";
|
||||
Coral::HostSettings settings =
|
||||
{
|
||||
.CoralDirectory = coralDir,
|
||||
.ExceptionCallback = ExceptionCallback
|
||||
};
|
||||
Coral::HostInstance hostInstance;
|
||||
hostInstance.Initialize(settings);
|
||||
|
||||
auto loadContext = hostInstance.CreateAssemblyLoadContext("NuakeEngineContext");
|
||||
auto& assembly = loadContext.LoadAssembly("NuakeNet.dll");
|
||||
|
||||
auto& assembly = m_LoadContext->LoadAssembly("NuakeNet.dll");
|
||||
|
||||
assembly.AddInternalCall("Nuake.Net.Engine", "LoggerLogIcall", reinterpret_cast<void*>(&Log));
|
||||
assembly.UploadInternalCalls();
|
||||
|
||||
auto& engineType = assembly.GetType("Nuake.Net.Engine");
|
||||
auto engineInstance = engineType.CreateInstance();
|
||||
engineInstance.InvokeMethod("Log");
|
||||
|
||||
Coral::NativeString param1 = Coral::NativeString::FromUTF8("Hello from CPP");;
|
||||
engineInstance.InvokeMethod("Log", param1);
|
||||
|
||||
engineInstance.Destroy();
|
||||
Coral::GC::Collect();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,22 @@
|
||||
#pragma once
|
||||
#include "src/Core/Core.h"
|
||||
|
||||
namespace Coral
|
||||
{
|
||||
class HostInstance;
|
||||
class AssemblyLoadContext;
|
||||
}
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class ScriptingEngineNet
|
||||
{
|
||||
private:
|
||||
ScriptingEngineNet() = default;
|
||||
~ScriptingEngineNet() = default;
|
||||
Scope<Coral::HostInstance> m_HostInstance;
|
||||
Scope<Coral::AssemblyLoadContext> m_LoadContext;
|
||||
|
||||
ScriptingEngineNet();
|
||||
~ScriptingEngineNet();
|
||||
|
||||
public:
|
||||
static ScriptingEngineNet& Get();
|
||||
|
||||
@@ -19,10 +19,9 @@ namespace Nuake.Net
|
||||
/// Prints a message to the console log
|
||||
/// </summary>
|
||||
/// <param name="message">message to be printed</param>
|
||||
public void Log()
|
||||
public void Log(NativeString input)
|
||||
{
|
||||
NativeString str = "Hello from C#";
|
||||
unsafe { LoggerLogIcall(str); }
|
||||
unsafe { LoggerLogIcall(input + " - hello from c# man"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user