Fixes for Visual Scripting interop via C# on new dotnet7 hosting
This commit is contained in:
@@ -798,10 +798,11 @@ namespace
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool VariantTypeEquals(const VariantType& type, MType* mType)
|
||||
bool VariantTypeEquals(const VariantType& type, MType* mType, bool isOut = false)
|
||||
{
|
||||
MClass* mClass = MCore::Type::GetClass(mType);
|
||||
if (MUtils::GetClass(type) != mClass)
|
||||
MClass* variantClass = MUtils::GetClass(type);
|
||||
if (variantClass != mClass)
|
||||
{
|
||||
// Hack for Vector2/3/4 which alias with Float2/3/4 or Double2/3/4 (depending on USE_LARGE_WORLDS)
|
||||
const auto& stdTypes = *StdTypesContainer::Instance();
|
||||
@@ -840,7 +841,7 @@ MMethod* ManagedBinaryModule::FindMethod(MClass* mclass, const ScriptingTypeMeth
|
||||
auto& param = signature.Params[paramIdx];
|
||||
MType* type = method->GetParameterType(paramIdx);
|
||||
if (param.IsOut != method->GetParameterIsOut(paramIdx) ||
|
||||
!VariantTypeEquals(param.Type, type))
|
||||
!VariantTypeEquals(param.Type, type, param.IsOut))
|
||||
{
|
||||
isValid = false;
|
||||
break;
|
||||
@@ -1289,8 +1290,8 @@ bool ManagedBinaryModule::InvokeMethod(void* method, const Variant& instance, Sp
|
||||
if (paramTypeHandle)
|
||||
{
|
||||
auto& valueType = paramTypeHandle.GetType();
|
||||
MISSING_CODE("TODO: reimplement unpacking managed structure out parameter from C# call");
|
||||
//valueType.Struct.Unbox(paramValue.AsBlob.Data, (MObject*)((byte*)param - sizeof(MonoObject))); // TODO: fix this for dotnet7
|
||||
MObject* boxed = MCore::Object::Box(param, valueType.ManagedClass);
|
||||
valueType.Struct.Unbox(paramValue.AsBlob.Data, boxed);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -147,6 +147,7 @@ public:
|
||||
{
|
||||
static ::String ToString(MType* type);
|
||||
static MClass* GetClass(MType* type);
|
||||
static MType* GetElementType(MType* type);
|
||||
static int32 GetSize(MType* type);
|
||||
static MTypes GetType(MType* type);
|
||||
static bool IsPointer(MType* type);
|
||||
|
||||
@@ -1166,6 +1166,12 @@ void* MUtils::VariantToManagedArgPtr(Variant& value, MType* type, bool& failed)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MTypes::Enum:
|
||||
{
|
||||
if (value.Type.Type != VariantType::Enum)
|
||||
return nullptr;
|
||||
return &value.AsUint64;
|
||||
}
|
||||
case MTypes::Class:
|
||||
{
|
||||
if (value.Type.Type == VariantType::Null)
|
||||
@@ -1183,7 +1189,8 @@ void* MUtils::VariantToManagedArgPtr(Variant& value, MType* type, bool& failed)
|
||||
if (value.Type.Type != VariantType::Array)
|
||||
return nullptr;
|
||||
MObject* object = BoxVariant(value);
|
||||
if (object && !MCore::Object::GetClass(object)->IsSubClassOf(MCore::Array::GetClass(MCore::Type::GetClass(type))))
|
||||
auto typeStr = MCore::Type::ToString(type);
|
||||
if (object && !MCore::Object::GetClass(object)->IsSubClassOf(MCore::Type::GetClass(type)))
|
||||
object = nullptr;
|
||||
return object;
|
||||
}
|
||||
|
||||
@@ -525,9 +525,17 @@ MObject* MCore::Exception::GetNotSupported(const char* msg)
|
||||
|
||||
MClass* MCore::Type::GetClass(MType* type)
|
||||
{
|
||||
static void* GetTypeClassPtr = GetStaticMethodPointer(TEXT("GetTypeClass"));
|
||||
type = (MType*)CallStaticMethod<void*, void*>(GetTypeClassPtr, type);
|
||||
return GetOrCreateClass(type);
|
||||
}
|
||||
|
||||
MType* MCore::Type::GetElementType(MType* type)
|
||||
{
|
||||
static void* GetElementClassPtr = GetStaticMethodPointer(TEXT("GetElementClass"));
|
||||
return (MType*)CallStaticMethod<void*, void*>(GetElementClassPtr, type);
|
||||
}
|
||||
|
||||
int32 MCore::Type::GetSize(MType* type)
|
||||
{
|
||||
return GetOrCreateClass(type)->GetInstanceSize();
|
||||
@@ -546,14 +554,14 @@ MTypes MCore::Type::GetType(MType* type)
|
||||
|
||||
bool MCore::Type::IsPointer(MType* type)
|
||||
{
|
||||
MISSING_CODE("TODO: MCore::Type::IsPointer"); // TODO: MCore::Type::IsPointer
|
||||
return false;
|
||||
static void* GetTypeIsPointerPtr = GetStaticMethodPointer(TEXT("GetTypeIsPointer"));
|
||||
return CallStaticMethod<bool, void*>(GetTypeIsPointerPtr, type);
|
||||
}
|
||||
|
||||
bool MCore::Type::IsReference(MType* type)
|
||||
{
|
||||
MISSING_CODE("TODO: MCore::Type::IsReference"); // TODO: MCore::Type::IsReference
|
||||
return false;
|
||||
static void* GetTypeIsReferencePtr = GetStaticMethodPointer(TEXT("GetTypeIsReference"));
|
||||
return CallStaticMethod<bool, void*>(GetTypeIsReferencePtr, type);
|
||||
}
|
||||
|
||||
const MAssembly::ClassesDictionary& MAssembly::GetClasses() const
|
||||
@@ -1256,7 +1264,7 @@ void* MMethod::GetThunk()
|
||||
|
||||
MMethod* MMethod::InflateGeneric() const
|
||||
{
|
||||
// TODO: implement/test this on .NET (eg. C# script that inherits other generic C# script which implements C++ native method)
|
||||
// This seams to be unused on .NET (Mono required inflating generic class of the script)
|
||||
return const_cast<MMethod*>(this);
|
||||
}
|
||||
|
||||
@@ -1355,13 +1363,16 @@ MMethod* MProperty::GetSetMethod() const
|
||||
|
||||
MObject* MProperty::GetValue(MObject* instance, MObject** exception) const
|
||||
{
|
||||
MISSING_CODE("TODO: MProperty::GetValue"); // TODO: MProperty::GetValue
|
||||
return nullptr;
|
||||
CHECK_RETURN(_getMethod, nullptr);
|
||||
return _getMethod->Invoke(instance, nullptr, exception);
|
||||
}
|
||||
|
||||
void MProperty::SetValue(MObject* instance, void* value, MObject** exception) const
|
||||
{
|
||||
MISSING_CODE("TODO: MProperty::SetValue"); // TODO: MProperty::SetValue
|
||||
CHECK(_setMethod);
|
||||
void* params[1];
|
||||
params[0] = value;
|
||||
_setMethod->Invoke(instance, params, exception);
|
||||
}
|
||||
|
||||
bool MProperty::HasAttribute(MClass* monoClass) const
|
||||
|
||||
@@ -928,6 +928,12 @@ MClass* MCore::Type::GetClass(MType* type)
|
||||
return FindClass(mclass);
|
||||
}
|
||||
|
||||
MType* MCore::Type::GetElementType(MType* type)
|
||||
{
|
||||
CRASH; // impl this (get type class and call GetElementClass)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32 MCore::Type::GetSize(MType* type)
|
||||
{
|
||||
int32 valueAlignment;
|
||||
|
||||
Reference in New Issue
Block a user