MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / VariantToManagedArgPtr

Method VariantToManagedArgPtr

Source/Engine/Scripting/ManagedCLR/MUtils.cpp:1050–1237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1048}
1049
1050void* MUtils::VariantToManagedArgPtr(Variant& value, MType* type, bool& failed)
1051{
1052 // Convert Variant into matching managed type and return pointer to data for the method invocation
1053 MTypes mType = MCore::Type::GetType(type);
1054 switch (mType)
1055 {
1056 case MTypes::Boolean:
1057 if (value.Type.Type != VariantType::Bool)
1058 value = (bool)value;
1059 return &value.AsBool;
1060 case MTypes::Char:
1061 case MTypes::I1:
1062 case MTypes::I2:
1063 if (value.Type.Type != VariantType::Int16)
1064 value = (int16)value;
1065 return &value.AsInt16;
1066 case MTypes::I4:
1067 if (value.Type.Type != VariantType::Int)
1068 value = (int32)value;
1069 return &value.AsInt;
1070 case MTypes::U1:
1071 case MTypes::U2:
1072 if (value.Type.Type != VariantType::Uint16)
1073 value = (uint16)value;
1074 return &value.AsUint16;
1075 case MTypes::U4:
1076 if (value.Type.Type != VariantType::Uint)
1077 value = (uint32)value;
1078 return &value.AsUint;
1079 case MTypes::I8:
1080 if (value.Type.Type != VariantType::Int64)
1081 value = (int64)value;
1082 return &value.AsInt64;
1083 case MTypes::U8:
1084 if (value.Type.Type != VariantType::Uint64)
1085 value = (uint64)value;
1086 return &value.AsUint64;
1087 case MTypes::R4:
1088 if (value.Type.Type != VariantType::Float)
1089 value = (float)value;
1090 return &value.AsFloat;
1091 case MTypes::R8:
1092 if (value.Type.Type != VariantType::Double)
1093 value = (double)value;
1094 return &value.AsDouble;
1095 case MTypes::String:
1096 return MUtils::ToString((StringView)value);
1097 case MTypes::ValueType:
1098 {
1099 MClass* klass = MCore::Type::GetClass(type);
1100 if (klass->IsEnum())
1101 {
1102 if (value.Type.Type != VariantType::Enum)
1103 {
1104 value.SetType(VariantType(VariantType::Enum, klass));
1105 value.AsUint64 = 0;
1106 }
1107 return &value.AsUint64;

Callers

nothing calls this directly

Calls 13

GetTypeFunction · 0.85
FindScriptingTypeFunction · 0.85
UnboxFunction · 0.85
ToStringFunction · 0.50
GetClassFunction · 0.50
VariantTypeClass · 0.50
InstanceClass · 0.50
StringAnsiViewClass · 0.50
StringFunction · 0.50
SetTypeMethod · 0.45
GetTypeMethod · 0.45
BoxMethod · 0.45

Tested by

no test coverage detected