Fix test
This commit is contained in:
@@ -732,6 +732,23 @@ ScriptingTypeHandle Scripting::FindScriptingType(const StringAnsiView& fullname)
|
|||||||
return ScriptingTypeHandle();
|
return ScriptingTypeHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScriptingObject* Scripting::NewObject(const ScriptingTypeHandle& type)
|
||||||
|
{
|
||||||
|
if (!type)
|
||||||
|
{
|
||||||
|
LOG(Error, "Invalid type.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
const ScriptingType& scriptingType = type.GetType();
|
||||||
|
|
||||||
|
// Create unmanaged object
|
||||||
|
const ScriptingObjectSpawnParams params(Guid::New(), type);
|
||||||
|
ScriptingObject* obj = scriptingType.Script.Spawn(params);
|
||||||
|
if (obj == nullptr)
|
||||||
|
LOG(Error, "Failed to spawn object of type \'{0}\'.", scriptingType.ToString());
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
ScriptingObject* Scripting::NewObject(const MClass* type)
|
ScriptingObject* Scripting::NewObject(const MClass* type)
|
||||||
{
|
{
|
||||||
if (type == nullptr)
|
if (type == nullptr)
|
||||||
@@ -762,10 +779,7 @@ ScriptingObject* Scripting::NewObject(const MClass* type)
|
|||||||
const ScriptingObjectSpawnParams params(Guid::New(), ScriptingTypeHandle(module, typeIndex));
|
const ScriptingObjectSpawnParams params(Guid::New(), ScriptingTypeHandle(module, typeIndex));
|
||||||
ScriptingObject* obj = scriptingType.Script.Spawn(params);
|
ScriptingObject* obj = scriptingType.Script.Spawn(params);
|
||||||
if (obj == nullptr)
|
if (obj == nullptr)
|
||||||
{
|
LOG(Error, "Failed to spawn object of type \'{0}\'.", scriptingType.ToString());
|
||||||
LOG(Error, "Failed to spawn object of type \'{0}.{1}\'.", String(mono_class_get_namespace(typeClass)), String(mono_class_get_name(typeClass)));
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return obj;
|
return obj;
|
||||||
#else
|
#else
|
||||||
LOG(Error, "Not supported object creation from Managed class.");
|
LOG(Error, "Not supported object creation from Managed class.");
|
||||||
|
|||||||
@@ -109,6 +109,13 @@ public:
|
|||||||
/// <returns>The scripting type or invalid type if missing.</returns>
|
/// <returns>The scripting type or invalid type if missing.</returns>
|
||||||
static ScriptingTypeHandle FindScriptingType(const StringAnsiView& fullname);
|
static ScriptingTypeHandle FindScriptingType(const StringAnsiView& fullname);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance of the given type object (native construction).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">The scripting object type class.</param>
|
||||||
|
/// <returns>The created object or null if failed.</returns>
|
||||||
|
static ScriptingObject* NewObject(const ScriptingTypeHandle& type);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the given class object (native construction).
|
/// Creates a new instance of the given class object (native construction).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ TEST_CASE("Scripting")
|
|||||||
// Test native class
|
// Test native class
|
||||||
ScriptingTypeHandle type = Scripting::FindScriptingType("FlaxEngine.TestClassNative");
|
ScriptingTypeHandle type = Scripting::FindScriptingType("FlaxEngine.TestClassNative");
|
||||||
CHECK(type == TestClassNative::TypeInitializer);
|
CHECK(type == TestClassNative::TypeInitializer);
|
||||||
ScriptingObject* object = Scripting::NewObject(type.GetType().ManagedClass);
|
ScriptingObject* object = Scripting::NewObject(type);
|
||||||
CHECK(object);
|
CHECK(object);
|
||||||
CHECK(object->Is<TestClassNative>());
|
CHECK(object->Is<TestClassNative>());
|
||||||
TestClassNative* testClass = (TestClassNative*)object;
|
TestClassNative* testClass = (TestClassNative*)object;
|
||||||
@@ -29,7 +29,7 @@ TEST_CASE("Scripting")
|
|||||||
// Test managed class
|
// Test managed class
|
||||||
type = Scripting::FindScriptingType("FlaxEngine.TestClassManaged");
|
type = Scripting::FindScriptingType("FlaxEngine.TestClassManaged");
|
||||||
CHECK(type);
|
CHECK(type);
|
||||||
object = Scripting::NewObject(type.GetType().ManagedClass);
|
object = Scripting::NewObject(type);
|
||||||
CHECK(object);
|
CHECK(object);
|
||||||
CHECK(object->Is<TestClassNative>());
|
CHECK(object->Is<TestClassNative>());
|
||||||
testClass = (TestClassNative*)object;
|
testClass = (TestClassNative*)object;
|
||||||
@@ -46,7 +46,7 @@ TEST_CASE("Scripting")
|
|||||||
{
|
{
|
||||||
ScriptingTypeHandle type = Scripting::FindScriptingType("FlaxEngine.TestClassManaged");
|
ScriptingTypeHandle type = Scripting::FindScriptingType("FlaxEngine.TestClassManaged");
|
||||||
CHECK(type);
|
CHECK(type);
|
||||||
ScriptingObject* object = Scripting::NewObject(type.GetType().ManagedClass);
|
ScriptingObject* object = Scripting::NewObject(type);
|
||||||
CHECK(object);
|
CHECK(object);
|
||||||
MObject* managed = object->GetOrCreateManagedInstance(); // Ensure to create C# object and run it's ctor
|
MObject* managed = object->GetOrCreateManagedInstance(); // Ensure to create C# object and run it's ctor
|
||||||
CHECK(managed);
|
CHECK(managed);
|
||||||
@@ -65,12 +65,13 @@ TEST_CASE("Scripting")
|
|||||||
CHECK(arr2[1].Vector == testClass->SimpleStruct.Vector);
|
CHECK(arr2[1].Vector == testClass->SimpleStruct.Vector);
|
||||||
CHECK(arr2[1].Object == testClass);
|
CHECK(arr2[1].Object == testClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Test Interface")
|
SECTION("Test Interface")
|
||||||
{
|
{
|
||||||
// Test native interface implementation
|
// Test native interface implementation
|
||||||
ScriptingTypeHandle type = Scripting::FindScriptingType("FlaxEngine.TestClassNative");
|
ScriptingTypeHandle type = Scripting::FindScriptingType("FlaxEngine.TestClassNative");
|
||||||
CHECK(type);
|
CHECK(type);
|
||||||
ScriptingObject* object = Scripting::NewObject(type.GetType().ManagedClass);
|
ScriptingObject* object = Scripting::NewObject(type);
|
||||||
CHECK(object);
|
CHECK(object);
|
||||||
TestClassNative* testClass = (TestClassNative*)object;
|
TestClassNative* testClass = (TestClassNative*)object;
|
||||||
int32 methodResult = testClass->TestInterfaceMethod(TEXT("123"));
|
int32 methodResult = testClass->TestInterfaceMethod(TEXT("123"));
|
||||||
@@ -86,7 +87,7 @@ TEST_CASE("Scripting")
|
|||||||
// Test managed interface override
|
// Test managed interface override
|
||||||
type = Scripting::FindScriptingType("FlaxEngine.TestClassManaged");
|
type = Scripting::FindScriptingType("FlaxEngine.TestClassManaged");
|
||||||
CHECK(type);
|
CHECK(type);
|
||||||
object = Scripting::NewObject(type.GetType().ManagedClass);
|
object = Scripting::NewObject(type);
|
||||||
CHECK(object);
|
CHECK(object);
|
||||||
testClass = (TestClassNative*)object;
|
testClass = (TestClassNative*)object;
|
||||||
methodResult = testClass->TestInterfaceMethod(TEXT("123"));
|
methodResult = testClass->TestInterfaceMethod(TEXT("123"));
|
||||||
@@ -102,7 +103,7 @@ TEST_CASE("Scripting")
|
|||||||
// Test managed interface implementation
|
// Test managed interface implementation
|
||||||
type = Scripting::FindScriptingType("FlaxEngine.TestInterfaceManaged");
|
type = Scripting::FindScriptingType("FlaxEngine.TestInterfaceManaged");
|
||||||
CHECK(type);
|
CHECK(type);
|
||||||
object = Scripting::NewObject(type.GetType().ManagedClass);
|
object = Scripting::NewObject(type);
|
||||||
CHECK(object);
|
CHECK(object);
|
||||||
interface = ScriptingObject::ToInterface<ITestInterface>(object);
|
interface = ScriptingObject::ToInterface<ITestInterface>(object);
|
||||||
CHECK(interface);
|
CHECK(interface);
|
||||||
|
|||||||
@@ -158,13 +158,13 @@ namespace Flax.Build.Bindings
|
|||||||
{
|
{
|
||||||
var wrapperName = GenerateCppWrapperNativeToVariantMethodName(typeInfo);
|
var wrapperName = GenerateCppWrapperNativeToVariantMethodName(typeInfo);
|
||||||
CppVariantFromTypes[wrapperName] = typeInfo;
|
CppVariantFromTypes[wrapperName] = typeInfo;
|
||||||
return $"VariantFrom{GenerateCppWrapperNativeToVariantMethodName(typeInfo)}Array({value}, {typeInfo.ArraySize})";
|
return $"VariantFrom{GenerateCppWrapperNativeToVariantMethodName(typeInfo)}Array((const {typeInfo}*){value}, {typeInfo.ArraySize})";
|
||||||
}
|
}
|
||||||
if (typeInfo.Type == "Array" && typeInfo.GenericArgs != null)
|
if (typeInfo.Type == "Array" && typeInfo.GenericArgs != null)
|
||||||
{
|
{
|
||||||
var wrapperName = GenerateCppWrapperNativeToVariantMethodName(typeInfo.GenericArgs[0]);
|
var wrapperName = GenerateCppWrapperNativeToVariantMethodName(typeInfo.GenericArgs[0]);
|
||||||
CppVariantFromTypes[wrapperName] = typeInfo;
|
CppVariantFromTypes[wrapperName] = typeInfo;
|
||||||
return $"VariantFrom{wrapperName}Array({value}.Get(), {value}.Count())";
|
return $"VariantFrom{wrapperName}Array((const {typeInfo.GenericArgs[0]}*){value}.Get(), {value}.Count())";
|
||||||
}
|
}
|
||||||
if (typeInfo.Type == "Dictionary" && typeInfo.GenericArgs != null)
|
if (typeInfo.Type == "Dictionary" && typeInfo.GenericArgs != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user