Add support for compiling and running engine without C# scripting

(configurable via `EngineConfiguration.UseCSharp` in Flax.Build)
This commit is contained in:
Wojtek Figat
2021-10-23 16:41:57 +02:00
parent 0b3d6b03ac
commit 8938f13a0b
86 changed files with 1244 additions and 688 deletions

View File

@@ -9,6 +9,9 @@
#include "Engine/Scripting/ManagedCLR/MClass.h"
#include "Engine/Threading/Threading.h"
#include "FlaxEngine.Gen.h"
#if USE_MONO
#include <ThirdParty/mono-2.0/mono/metadata/exception.h>
#include <ThirdParty/mono-2.0/mono/metadata/appdomain.h>
@@ -61,8 +64,11 @@ bool CacheMethods()
return false;
}
#endif
void DebugLog::Log(LogType type, const StringView& message)
{
#if USE_MONO
if (CacheMethods())
return;
@@ -77,34 +83,41 @@ void DebugLog::Log(LogType type, const StringView& message)
params.AddParam(stackTrace, scriptsDomain->GetNative());
#endif
MainThreadManagedInvokeAction::Invoke(Internal_SendLog, params);
#endif
}
void DebugLog::LogException(MonoObject* exceptionObject)
void DebugLog::LogException(MObject* exceptionObject)
{
#if USE_MONO
if (exceptionObject == nullptr || CacheMethods())
return;
MainThreadManagedInvokeAction::ParamsBuilder params;
params.AddParam(exceptionObject);
MainThreadManagedInvokeAction::Invoke(Internal_SendLogException, params);
#endif
}
String DebugLog::GetStackTrace()
{
String result;
#if USE_MONO
if (!CacheMethods())
{
auto stackTraceObj = Internal_GetStackTrace->Invoke(nullptr, nullptr, nullptr);
MUtils::ToString((MonoString*)stackTraceObj, result);
}
#endif
return result;
}
void DebugLog::ThrowException(const char* msg)
{
#if USE_MONO
// Throw exception to the C# world
auto ex = mono_exception_from_name_msg(mono_get_corlib(), "System", "Exception", msg);
mono_raise_exception(ex);
#endif
}
void DebugLog::ThrowNullReference()
@@ -112,35 +125,45 @@ void DebugLog::ThrowNullReference()
//LOG(Warning, "Invalid null reference.");
//LOG_STR(Warning, DebugLog::GetStackTrace());
#if USE_MONO
// Throw exception to the C# world
auto ex = mono_get_exception_null_reference();
mono_raise_exception(ex);
#endif
}
void DebugLog::ThrowArgument(const char* arg, const char* msg)
{
#if USE_MONO
// Throw exception to the C# world
auto ex = mono_get_exception_argument(arg, msg);
mono_raise_exception(ex);
#endif
}
void DebugLog::ThrowArgumentNull(const char* arg)
{
#if USE_MONO
// Throw exception to the C# world
auto ex = mono_get_exception_argument_null(arg);
mono_raise_exception(ex);
#endif
}
void DebugLog::ThrowArgumentOutOfRange(const char* arg)
{
#if USE_MONO
// Throw exception to the C# world
auto ex = mono_get_exception_argument_out_of_range(arg);
mono_raise_exception(ex);
#endif
}
void DebugLog::ThrowNotSupported(const char* msg)
{
#if USE_MONO
// Throw exception to the C# world
auto ex = mono_get_exception_not_supported(msg);
mono_raise_exception(ex);
#endif
}