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

Document or disallow extension attributes/methods #107

Open
AutonomicPerfectionist opened this issue Aug 8, 2023 · 1 comment · May be fixed by #108
Open

Document or disallow extension attributes/methods #107

AutonomicPerfectionist opened this issue Aug 8, 2023 · 1 comment · May be fixed by #108
Labels
enhancement New feature or request

Comments

@AutonomicPerfectionist
Copy link
Contributor

Is your feature request related to a problem? Please describe.
It seems that CMakePPLang classes support a feature called "extension attributes/methods" in other languages like Kotlin or C#. The feature allows external parties to define additional methods and attributes on a class outside of the cpp_class/cpp_end_class fences. I believe support for this feature is merely a byproduct of how classes were implemented, but nevertheless, I could not find any documentation on it.

Example usage:

cpp_class(MyClass)
    cpp_attr(MyClass a 1)
    cpp_attr(MyClass b 2)
cpp_end_class()

# Create instance
MyClass(CTOR my_instance)

# In a different file

# Add a new attribute
cpp_attr(MyClass c 4)

# Set attribute as single value, noting that
# the instance we created earlier now has the new attribute
MyClass(SET "${my_instance}" c 3)

# Get the value and ensure it was set correctly
MyClass(GET "${my_instance}" res c)
ct_assert_equal(res 3)

Describe the solution you'd like
I think it would be wise to at least document the current ability to use extension attributes/methods, perhaps adding that such usage is unstable and not guaranteed to work in future versions unless we desire to officially support them. Otherwise, it might be a good idea to explicitly disallow them, which can be done by "freezing" a class's definition upon calling cpp_end_class().

This issue is very low priority, mainly I'm just writing it down because I made the observation and wondered if such usage was officially supported or not.

@AutonomicPerfectionist AutonomicPerfectionist added the enhancement New feature or request label Aug 8, 2023
@ryanmrichard
Copy link
Contributor

CMakePPLang is modeled after Python, which also supports extension methods/attributes. I don't foresee us changing how classes are implemented in CMakePPLang, so I think we may as well make this a supported feature, especially since we get it more or less for free.

@AutonomicPerfectionist AutonomicPerfectionist linked a pull request Aug 9, 2023 that will close this issue
3 tasks
@AutonomicPerfectionist AutonomicPerfectionist linked a pull request Aug 9, 2023 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants