Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug that causes properties in base type of one derived structure type not get serialized/deserialized. #84

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Modules/Luna/Runtime/Reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,16 @@ namespace Luna
//! * `type` must specify one valid type object.
LUNA_RUNTIME_API Span<const StructurePropertyDesc> get_struct_properties(typeinfo_t type);

//! Gets properties of the specified structure.
//! @param[in] type The type to query.
//! @param[out] out_properties Returns properties of the specified structure. Existing elements in the vector will not be modified.
//! If `type` is not a structure or generic structure instanced type, this vector is not changed.
//! @param[in] include_base_type Whether to query properties that belongs to the base type of this structure type if this structure type has
//! base type. If this is `false`, only properties that belongs to this type (not the base type) will be returned.
//! @par Valid Usage
//! * `type` must specify one valid type object.
LUNA_RUNTIME_API void get_struct_properties(typeinfo_t type, Vector<StructurePropertyDesc>& out_properties, bool include_base_type = true);

//! Gets the base type of the specified type.
//! @param[in] type The type to query.
//! @return Returns the base type of the specified type.
Expand Down
6 changes: 4 additions & 2 deletions Modules/Luna/Runtime/Source/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace Luna
Variant ret(VariantType::object);
lutry
{
auto properties = get_struct_properties(type);
Vector<StructurePropertyDesc> properties;
get_struct_properties(type, properties);
for(auto& prop : properties)
{
if (is_type_serializable(prop.type))
Expand All @@ -38,7 +39,8 @@ namespace Luna
{
lutry
{
auto properties = get_struct_properties(type);
Vector<StructurePropertyDesc> properties;
get_struct_properties(type, properties);
for(auto& prop : properties)
{
auto& prop_data = data[prop.name];
Expand Down
28 changes: 28 additions & 0 deletions Modules/Luna/Runtime/Source/TypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,34 @@ namespace Luna
}
return Span<const StructurePropertyDesc>();
}
LUNA_RUNTIME_API void get_struct_properties(typeinfo_t type, Vector<StructurePropertyDesc>& out_properties, bool include_base_type)
{
TypeInfo* t = (TypeInfo*)type;
switch (t->kind)
{
case TypeKind::structure:
{
StructureTypeInfo* type = (StructureTypeInfo*)t;
if(include_base_type && type->base_type)
{
get_struct_properties(type->base_type, out_properties, true);
}
out_properties.insert(out_properties.end(), type->property_descs.begin(), type->property_descs.end());
break;
}
case TypeKind::generic_structure_instanced:
{
GenericStructureInstancedTypeInfo* type = (GenericStructureInstancedTypeInfo*)t;
if(include_base_type && type->base_type)
{
get_struct_properties(type->base_type, out_properties, true);
}
out_properties.insert(out_properties.end(), type->property_descs.begin(), type->property_descs.end());
break;
}
default: break;
}
}
LUNA_RUNTIME_API typeinfo_t get_base_type(typeinfo_t type)
{
TypeInfo* t = (TypeInfo*)type;
Expand Down
Loading