Fix engine with c# scripting disabled

This commit is contained in:
Wojtek Figat
2024-05-14 13:13:37 +02:00
parent a742ce1d32
commit 3ae30a59b3
3 changed files with 55 additions and 0 deletions

View File

@@ -253,6 +253,41 @@ MObject* MCore::Exception::GetNotSupported(const char* msg)
return nullptr;
}
::String MCore::Type::ToString(MType* type)
{
return ::String::Empty;
}
MClass* MCore::Type::GetClass(MType* type)
{
return nullptr;
}
MType* MCore::Type::GetElementType(MType* type)
{
return nullptr;
}
int32 MCore::Type::GetSize(MType* type)
{
return 0;
}
MTypes MCore::Type::GetType(MType* type)
{
return MTypes::End;
}
bool MCore::Type::IsPointer(MType* type)
{
return false;
}
bool MCore::Type::IsReference(MType* type)
{
return false;
}
const MAssembly::ClassesDictionary& MAssembly::GetClasses() const
{
_hasCachedClasses = true;

View File

@@ -260,7 +260,11 @@ ScriptingObject* ScriptingObject::ToNative(MObject* obj)
bool ScriptingObject::Is(const ScriptingTypeHandle& type) const
{
CHECK_RETURN(type, false);
#if SCRIPTING_OBJECT_CAST_WITH_CSHARP
return _type == type || CanCast(GetClass(), type.GetType().ManagedClass);
#else
return CanCast(GetTypeHandle(), type);
#endif
}
void ScriptingObject::ChangeID(const Guid& newId)
@@ -421,10 +425,16 @@ void ScriptingObject::UnregisterObject()
bool ScriptingObject::CanCast(const ScriptingTypeHandle& from, const ScriptingTypeHandle& to)
{
if (from == to)
return true;
if (!from && !to)
return true;
CHECK_RETURN(from && to, false);
#if SCRIPTING_OBJECT_CAST_WITH_CSHARP
return CanCast(from.GetType().ManagedClass, to.GetType().ManagedClass);
#else
return to.IsAssignableFrom(from);
#endif
}
bool ScriptingObject::CanCast(const MClass* from, const MClass* to)

View File

@@ -7,6 +7,8 @@
#include "Engine/Core/Delegate.h"
#include "ManagedCLR/MTypes.h"
#define SCRIPTING_OBJECT_CAST_WITH_CSHARP (USE_CSHARP)
/// <summary>
/// Represents object from unmanaged memory that can use accessed via scripting.
/// </summary>
@@ -156,7 +158,11 @@ public:
template<typename T>
static T* Cast(ScriptingObject* obj)
{
#if SCRIPTING_OBJECT_CAST_WITH_CSHARP
return obj && CanCast(obj->GetClass(), T::GetStaticClass()) ? static_cast<T*>(obj) : nullptr;
#else
return obj && CanCast(obj->GetTypeHandle(), T::TypeInitializer) ? static_cast<T*>(obj) : nullptr;
#endif
}
bool Is(const ScriptingTypeHandle& type) const;
@@ -169,7 +175,11 @@ public:
template<typename T>
bool Is() const
{
#if SCRIPTING_OBJECT_CAST_WITH_CSHARP
return CanCast(GetClass(), T::GetStaticClass());
#else
return CanCast(GetTypeHandle(), T::TypeInitializer);
#endif
}
public: