Add GetFields and GetMethods to binary module api
This commit is contained in:
@@ -1212,6 +1212,16 @@ bool ManagedBinaryModule::IsLoaded() const
|
||||
#endif
|
||||
}
|
||||
|
||||
void ManagedBinaryModule::GetMethods(const ScriptingTypeHandle& typeHandle, Array<void*>& methods)
|
||||
{
|
||||
const ScriptingType& type = typeHandle.GetType();
|
||||
if (type.ManagedClass)
|
||||
{
|
||||
const auto& mMethods = type.ManagedClass->GetMethods();
|
||||
methods.Add((void* const*)mMethods.Get(), mMethods.Count());
|
||||
}
|
||||
}
|
||||
|
||||
void* ManagedBinaryModule::FindMethod(const ScriptingTypeHandle& typeHandle, const StringAnsiView& name, int32 numParams)
|
||||
{
|
||||
const ScriptingType& type = typeHandle.GetType();
|
||||
@@ -1379,6 +1389,23 @@ void ManagedBinaryModule::GetMethodSignature(void* method, ScriptingTypeMethodSi
|
||||
#else
|
||||
#define ManagedBinaryModuleFieldIsPropertyBit (uintptr)(1ul << 31)
|
||||
#endif
|
||||
#define GetManagedBinaryModulePropertyHandle(ptr) ((uintptr)ptr & ~ManagedBinaryModuleFieldIsPropertyBit)
|
||||
#define SetManagedBinaryModulePropertyHandle(ptr) (void*)((uintptr)ptr | ManagedBinaryModuleFieldIsPropertyBit)
|
||||
|
||||
void ManagedBinaryModule::GetFields(const ScriptingTypeHandle& typeHandle, Array<void*>& fields)
|
||||
{
|
||||
const ScriptingType& type = typeHandle.GetType();
|
||||
if (type.ManagedClass)
|
||||
{
|
||||
const auto& mFields = type.ManagedClass->GetFields();
|
||||
const auto& mProperties = type.ManagedClass->GetProperties();
|
||||
fields.EnsureCapacity(fields.Count() + mFields.Count() + mProperties.Count());
|
||||
for (MField* field : mFields)
|
||||
fields.Add(field);
|
||||
for (MProperty* property : mProperties)
|
||||
fields.Add(SetManagedBinaryModulePropertyHandle(property));
|
||||
}
|
||||
}
|
||||
|
||||
void* ManagedBinaryModule::FindField(const ScriptingTypeHandle& typeHandle, const StringAnsiView& name)
|
||||
{
|
||||
@@ -1388,7 +1415,7 @@ void* ManagedBinaryModule::FindField(const ScriptingTypeHandle& typeHandle, cons
|
||||
{
|
||||
result = type.ManagedClass->GetProperty(name.Get());
|
||||
if (result)
|
||||
result = (void*)((uintptr)result | ManagedBinaryModuleFieldIsPropertyBit);
|
||||
result = SetManagedBinaryModulePropertyHandle(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1398,7 +1425,7 @@ void ManagedBinaryModule::GetFieldSignature(void* field, ScriptingTypeFieldSigna
|
||||
#if USE_CSHARP
|
||||
if ((uintptr)field & ManagedBinaryModuleFieldIsPropertyBit)
|
||||
{
|
||||
const auto mProperty = (MProperty*)((uintptr)field & ~ManagedBinaryModuleFieldIsPropertyBit);
|
||||
const auto mProperty = (MProperty*)GetManagedBinaryModulePropertyHandle(field);
|
||||
fieldSignature.Name = mProperty->GetName();
|
||||
fieldSignature.ValueType = MoveTemp(MUtils::UnboxVariantType(mProperty->GetType()));
|
||||
fieldSignature.IsStatic = mProperty->IsStatic();
|
||||
|
||||
@@ -115,6 +115,15 @@ public:
|
||||
return TypeNameToTypeIndex.TryGet(typeName, typeIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets handles of all method in a given scripting type.
|
||||
/// </summary>
|
||||
/// <param name="typeHandle">The type to find methods inside it.</param>
|
||||
/// <param name="methods">The output list of method pointers.</param>
|
||||
virtual void GetMethods(const ScriptingTypeHandle& typeHandle, Array<void*>& methods)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find a method in a given scripting type by the method name and parameters count.
|
||||
/// </summary>
|
||||
@@ -158,6 +167,15 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets handles of all fields in a given scripting type.
|
||||
/// </summary>
|
||||
/// <param name="typeHandle">The type to find fields inside it.</param>
|
||||
/// <param name="fields">The output list of field pointers.</param>
|
||||
virtual void GetFields(const ScriptingTypeHandle& typeHandle, Array<void*>& fields)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find a field in a given scripting type by the field name.
|
||||
/// </summary>
|
||||
@@ -318,10 +336,12 @@ public:
|
||||
// [BinaryModule]
|
||||
const StringAnsi& GetName() const override;
|
||||
bool IsLoaded() const override;
|
||||
void GetMethods(const ScriptingTypeHandle& typeHandle, Array<void*>& methods) override;
|
||||
void* FindMethod(const ScriptingTypeHandle& typeHandle, const StringAnsiView& name, int32 numParams = 0) override;
|
||||
void* FindMethod(const ScriptingTypeHandle& typeHandle, const ScriptingTypeMethodSignature& signature) override;
|
||||
bool InvokeMethod(void* method, const Variant& instance, Span<Variant> paramValues, Variant& result) override;
|
||||
void GetMethodSignature(void* method, ScriptingTypeMethodSignature& signature) override;
|
||||
void GetFields(const ScriptingTypeHandle& typeHandle, Array<void*>& fields) override;
|
||||
void* FindField(const ScriptingTypeHandle& typeHandle, const StringAnsiView& name) override;
|
||||
void GetFieldSignature(void* field, ScriptingTypeFieldSignature& fieldSignature) override;
|
||||
bool GetFieldValue(void* field, const Variant& instance, Variant& result) override;
|
||||
|
||||
Reference in New Issue
Block a user