1601 lines
56 KiB
C++
1601 lines
56 KiB
C++
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
|
|
|
#include "BinaryModule.h"
|
|
#include "ScriptingObject.h"
|
|
#include "Engine/Core/Log.h"
|
|
#include "Engine/Threading/Threading.h"
|
|
#include "Engine/Profiler/ProfilerCPU.h"
|
|
#include "ManagedCLR/MAssembly.h"
|
|
#include "ManagedCLR/MClass.h"
|
|
#include "ManagedCLR/MMethod.h"
|
|
#include "ManagedCLR/MField.h"
|
|
#include "ManagedCLR/MProperty.h"
|
|
#include "ManagedCLR/MUtils.h"
|
|
#include "ManagedCLR/MException.h"
|
|
#include "FlaxEngine.Gen.h"
|
|
#include "Scripting.h"
|
|
#include "Events.h"
|
|
#include "Internal/StdTypesContainer.h"
|
|
|
|
Dictionary<Pair<ScriptingTypeHandle, StringView>, void(*)(ScriptingObject*, void*, bool)> ScriptingEvents::EventsTable;
|
|
Delegate<ScriptingObject*, Span<Variant>, ScriptingTypeHandle, StringView> ScriptingEvents::Event;
|
|
|
|
ManagedBinaryModule* GetBinaryModuleCorlib()
|
|
{
|
|
#if COMPILE_WITHOUT_CSHARP
|
|
return nullptr;
|
|
#else
|
|
static ManagedBinaryModule assembly("corlib");
|
|
return &assembly;
|
|
#endif
|
|
}
|
|
|
|
ScriptingTypeHandle::ScriptingTypeHandle(const ScriptingTypeInitializer& initializer)
|
|
: Module(initializer.Module)
|
|
, TypeIndex(initializer.TypeIndex)
|
|
{
|
|
}
|
|
|
|
String ScriptingTypeHandle::ToString(bool withAssembly) const
|
|
{
|
|
String result = GetType().ToString();
|
|
if (withAssembly)
|
|
{
|
|
result += TEXT("(module ");
|
|
result += String(Module->GetName());
|
|
result += TEXT(")");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
const ScriptingType& ScriptingTypeHandle::GetType() const
|
|
{
|
|
ASSERT_LOW_LAYER(Module);
|
|
return Module->Types[TypeIndex];
|
|
}
|
|
|
|
#if USE_CSHARP
|
|
|
|
MClass* ScriptingTypeHandle::GetClass() const
|
|
{
|
|
ASSERT_LOW_LAYER(Module && Module->Types[TypeIndex].ManagedClass);
|
|
return Module->Types[TypeIndex].ManagedClass;
|
|
}
|
|
|
|
#endif
|
|
|
|
bool ScriptingTypeHandle::IsSubclassOf(ScriptingTypeHandle c) const
|
|
{
|
|
auto type = *this;
|
|
if (type == c)
|
|
return false;
|
|
for (; type; type = type.GetType().GetBaseType())
|
|
{
|
|
if (type == c)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool ScriptingTypeHandle::IsAssignableFrom(ScriptingTypeHandle c) const
|
|
{
|
|
while (c)
|
|
{
|
|
if (c == *this)
|
|
return true;
|
|
c = c.GetType().GetBaseType();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool ScriptingTypeHandle::operator==(const ScriptingTypeInitializer& other) const
|
|
{
|
|
return Module == other.Module && TypeIndex == other.TypeIndex;
|
|
}
|
|
|
|
bool ScriptingTypeHandle::operator!=(const ScriptingTypeInitializer& other) const
|
|
{
|
|
return Module != other.Module || TypeIndex != other.TypeIndex;
|
|
}
|
|
|
|
ScriptingType::ScriptingType()
|
|
: ManagedClass(nullptr)
|
|
, Module(nullptr)
|
|
, InitRuntime(nullptr)
|
|
, Fullname(nullptr, 0)
|
|
, Type(ScriptingTypes::Script)
|
|
, BaseTypePtr(nullptr)
|
|
, Interfaces(nullptr)
|
|
{
|
|
Script.Spawn = nullptr;
|
|
Script.VTable = nullptr;
|
|
Script.InterfacesOffsets = nullptr;
|
|
Script.ScriptVTable = nullptr;
|
|
Script.ScriptVTableBase = nullptr;
|
|
Script.SetupScriptVTable = nullptr;
|
|
Script.SetupScriptObjectVTable = nullptr;
|
|
Script.DefaultInstance = nullptr;
|
|
}
|
|
|
|
ScriptingType::ScriptingType(const StringAnsiView& fullname, BinaryModule* module, int32 size, InitRuntimeHandler initRuntime, SpawnHandler spawn, const ScriptingTypeHandle& baseType, SetupScriptVTableHandler setupScriptVTable, SetupScriptObjectVTableHandler setupScriptObjectVTable, const InterfaceImplementation* interfaces)
|
|
: ManagedClass(nullptr)
|
|
, Module(module)
|
|
, InitRuntime(initRuntime)
|
|