Add ScriptingTypeHandle support for scripting bindings as System.Type
This commit is contained in:
@@ -186,6 +186,29 @@ MonoString* MUtils::ToString(const StringView& str, MonoDomain* domain)
|
|||||||
return mono_string_new_utf16(domain, (const mono_unichar2*)*str, str.Length());
|
return mono_string_new_utf16(domain, (const mono_unichar2*)*str, str.Length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScriptingTypeHandle MUtils::UnboxScriptingTypeHandle(MonoReflectionType* value)
|
||||||
|
{
|
||||||
|
MonoClass* klass = GetClass(value);
|
||||||
|
if (!klass)
|
||||||
|
return ScriptingTypeHandle();
|
||||||
|
const MString typeName = MUtils::GetClassFullname(klass);
|
||||||
|
const ScriptingTypeHandle typeHandle = Scripting::FindScriptingType(typeName);
|
||||||
|
if (!typeHandle)
|
||||||
|
LOG(Warning, "Unknown scripting type {}", String(typeName));
|
||||||
|
return typeHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
MonoReflectionType* MUtils::BoxScriptingTypeHandle(const ScriptingTypeHandle& value)
|
||||||
|
{
|
||||||
|
MonoReflectionType* result = nullptr;
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
MonoType* monoType = mono_class_get_type(value.GetType().ManagedClass->GetNative());
|
||||||
|
result = mono_type_get_object(mono_domain_get(), monoType);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
VariantType MUtils::UnboxVariantType(MonoReflectionType* value)
|
VariantType MUtils::UnboxVariantType(MonoReflectionType* value)
|
||||||
{
|
{
|
||||||
if (value == nullptr)
|
if (value == nullptr)
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ namespace MUtils
|
|||||||
extern FLAXENGINE_API MonoString* ToString(const StringView& str);
|
extern FLAXENGINE_API MonoString* ToString(const StringView& str);
|
||||||
extern FLAXENGINE_API MonoString* ToString(const StringView& str, MonoDomain* domain);
|
extern FLAXENGINE_API MonoString* ToString(const StringView& str, MonoDomain* domain);
|
||||||
|
|
||||||
|
extern FLAXENGINE_API ScriptingTypeHandle UnboxScriptingTypeHandle(MonoReflectionType* value);
|
||||||
|
extern FLAXENGINE_API MonoReflectionType* BoxScriptingTypeHandle(const ScriptingTypeHandle& value);
|
||||||
extern FLAXENGINE_API VariantType UnboxVariantType(MonoReflectionType* value);
|
extern FLAXENGINE_API VariantType UnboxVariantType(MonoReflectionType* value);
|
||||||
extern FLAXENGINE_API VariantType UnboxVariantType(MonoType* monoType);
|
extern FLAXENGINE_API VariantType UnboxVariantType(MonoType* monoType);
|
||||||
extern FLAXENGINE_API MonoReflectionType* BoxVariantType(const VariantType& value);
|
extern FLAXENGINE_API MonoReflectionType* BoxVariantType(const VariantType& value);
|
||||||
|
|||||||
@@ -174,14 +174,22 @@ namespace Flax.Build.Bindings
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Skip for special types
|
// Skip for special types
|
||||||
if (typeInfo.Type == "BytesContainer" && typeInfo.GenericArgs == null)
|
if (typeInfo.GenericArgs == null)
|
||||||
return false;
|
{
|
||||||
if (typeInfo.Type == "Variant" && typeInfo.GenericArgs == null)
|
if (typeInfo.Type == "BytesContainer")
|
||||||
return false;
|
return false;
|
||||||
if (typeInfo.Type == "VariantType" && typeInfo.GenericArgs == null)
|
if (typeInfo.Type == "Variant")
|
||||||
return false;
|
return false;
|
||||||
if (typeInfo.Type == "Function" && typeInfo.GenericArgs != null)
|
if (typeInfo.Type == "VariantType")
|
||||||
return false;
|
return false;
|
||||||
|
if (typeInfo.Type == "ScriptingTypeHandle")
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (typeInfo.Type == "Function")
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Find API type info
|
// Find API type info
|
||||||
var apiType = FindApiTypeInfo(buildData, typeInfo, caller);
|
var apiType = FindApiTypeInfo(buildData, typeInfo, caller);
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ namespace Flax.Build.Bindings
|
|||||||
{ "StringAnsi", "string" },
|
{ "StringAnsi", "string" },
|
||||||
{ "StringAnsiView", "string" },
|
{ "StringAnsiView", "string" },
|
||||||
{ "ScriptingObject", "FlaxEngine.Object" },
|
{ "ScriptingObject", "FlaxEngine.Object" },
|
||||||
|
{ "ScriptingTypeHandle", "System.Type" },
|
||||||
{ "PersistentScriptingObject", "FlaxEngine.Object" },
|
{ "PersistentScriptingObject", "FlaxEngine.Object" },
|
||||||
{ "ManagedScriptingObject", "FlaxEngine.Object" },
|
{ "ManagedScriptingObject", "FlaxEngine.Object" },
|
||||||
{ "MClass", "System.Type" },
|
{ "MClass", "System.Type" },
|
||||||
|
|||||||
@@ -407,6 +407,9 @@ namespace Flax.Build.Bindings
|
|||||||
case "VariantType":
|
case "VariantType":
|
||||||
type = "MonoReflectionType*";
|
type = "MonoReflectionType*";
|
||||||
return "MUtils::BoxVariantType({0})";
|
return "MUtils::BoxVariantType({0})";
|
||||||
|
case "ScriptingTypeHandle":
|
||||||
|
type = "MonoReflectionType*";
|
||||||
|
return "MUtils::BoxScriptingTypeHandle({0})";
|
||||||
case "ScriptingObject":
|
case "ScriptingObject":
|
||||||
case "ManagedScriptingObject":
|
case "ManagedScriptingObject":
|
||||||
case "PersistentScriptingObject":
|
case "PersistentScriptingObject":
|
||||||
@@ -590,6 +593,9 @@ namespace Flax.Build.Bindings
|
|||||||
case "VariantType":
|
case "VariantType":
|
||||||
type = "MonoReflectionType*";
|
type = "MonoReflectionType*";
|
||||||
return "MUtils::UnboxVariantType({0})";
|
return "MUtils::UnboxVariantType({0})";
|
||||||
|
case "ScriptingTypeHandle":
|
||||||
|
type = "MonoReflectionType*";
|
||||||
|
return "MUtils::UnboxScriptingTypeHandle({0})";
|
||||||
case "CultureInfo":
|
case "CultureInfo":
|
||||||
type = "void*";
|
type = "void*";
|
||||||
return "MUtils::ToNative({0})";
|
return "MUtils::ToNative({0})";
|
||||||
|
|||||||
Reference in New Issue
Block a user