-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
C#: Add version defines to help users deal with breaking changes #78249
Conversation
This is great to have, so that C# add-ons can support multiple Godot versions more easily 🙂 Should it be |
.NET uses |
One the other hand unity uses It is pretty much a whatever, both work, tho and I don't really have a strong opinion either way. |
Does C# support giving values to defines and doing simple comparisons in Because we already have a hex-encoded version number that can be used for any complex comparison logic without having to make multiple defines for major, minor, patch and So the example would be: #if GODOT_VERSION >= 0x040100 For the record that's what third-party C++ modules do. If that's hard to parse for some, we can also add a macro like Maintaining a list like this manually seems like a hassle, and one more thing to bump everytime we make a release.
About that list, what happens if someone used |
The C# preprocessor is extremely limited, it only supports If they used Also if there was a feature that was added in 4.3 and then cherry-picked to 4.2.1 and 4.1.7 the checks would become really complicated, if the patch version defines for previous minor versions were included. |
I see. It's a shame that the C# preprocessor is so limited. I'm still not sure how people would effectively use patch version defines without break forward compatibility with future minor versions. Would |
Exactly. Basically for C# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me given the constraints of the C# preprocessor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We should consider backporting to 4.0 as Calinou suggested, in which case we'll want to add those defines here as well.
b2707a2
to
1b466c6
Compare
Thanks! |
vs 2022 17.6.2 + dotnet 7 After I tried to remove the newline, it was all right
|
Adds an easy way to write C# scripts that work with multiple godot versions with breaking changes between, for example for scripts distributed via the asset library.
Such version defines are pretty common for C# and both the .net runtime and Unity have them in pretty the same form (https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#conditional-compilation, https://docs.unity3d.com/Manual/PlatformDependentCompilation.html)
While this can largely be done with runtime version checks and untyped code instead, in C# (unlike in GDScript) this is pretty painful and completely different from how code is normally written.
Example Usage:
While it is pretty late for 4.1, this change is pretty much zero risk and the more versions don't support this the less useful this becomes.
The defines have to be manually updated when changing versions. It is probably possible to automatically generate these, but that is unnecessarily complex for a first version.
The defines added are one for the major, minor, and patch of the current version, and then OR_GREATER defines from 0 to the current value for each component, if these defines have existed in that version.
Examples: for 4.3.2:
GODOT4
,GODOT4_OR_GREATER
,GODOT4_3
,GODOT4_1_OR_GREATER
,GODOT4_2_OR_GREATER
,GODOT4_3_OR_GREATER
,GODOT4_3_2
,GODOT4_3_0_OR_GREATER
,GODOT4_3_1_OR_GREATER
, andGODOT4_3_2_OR_GREATER
for 5.0.1:
GODOT5
,GODOT4_OR_GREATER
,GODOT5_OR_GREATER
,GODOT5_0
,GODOT5_0_OR_GREATER
,GODOT5_0_2
,GODOT5_0_0_OR_GREATER
, andGODOT5_0_1_OR_GREATER