Skip to content

Commit

Permalink
Allow adding enum options
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Nov 7, 2024
1 parent 972b3bf commit ca8e2c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/Reflection/ReflectionEnum.reds
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
public native class ReflectionEnum extends ReflectionType {
public native func GetConstants() -> array<ref<ReflectionConst>>
public native func IsNative() -> Bool
public native func AddConstant(name: CName, value: Int64)
}

public native class ReflectionConst {
Expand Down
13 changes: 13 additions & 0 deletions src/App/Reflection/ReflectionEnum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ struct ReflectionEnum : ReflectionType
return !m_enum->flags.isScripted;
}

void AddConstant(Red::CName aName, int64_t aValue) const
{
for (uint32_t i = 0; i != m_enum->valueList.size; ++i)
{
if (aValue == m_enum->valueList.entries[i] || aName == m_enum->hashList.entries[i])
return;
}

m_enum->valueList.PushBack(aValue);
m_enum->hashList.PushBack(aName);
}

Red::CEnum* m_enum;

RTTI_IMPL_TYPEINFO(App::ReflectionEnum);
Expand All @@ -77,4 +89,5 @@ RTTI_DEFINE_CLASS(App::ReflectionEnum, {
RTTI_PARENT(App::ReflectionType);
RTTI_METHOD(GetConstants);
RTTI_METHOD(IsNative);
RTTI_METHOD(AddConstant);
});

0 comments on commit ca8e2c4

Please sign in to comment.