-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add support of custom values for [flag]
enums
#19774
Comments
How would that work with something like [flag]
enum Foo {
my_enum = 237
} ? V would have to exhaustively check every custom value to make certain they resolve to a single bit. Not sure what it should do with enums with duplicate values... that could probably be allowed, though it could be confusing. enum Foo {
foo = 1
bar = 1
baz = 1
} |
Idk, probably the same way it works in C |
A flag in V is meant to be a single bit, so it doesn't match up with what C does. |
So this issues is a proposition to change that or implement another way to match flags in C - otherwise this will be another problem with usage of C code/libs in V (at least, maybe there are other real world cases) |
An enum that isn't a single bit isn't a flag, it's just an enum. Do you have an example of C code that you're thinking about? |
Here is an example (C code) typedef enum TS_WindowFlags {
TS_WindowFlagNone = 0,
TS_WindowFlagTitle = 1,
TS_WindowFlagClose = 2,
TS_WindowFlagFrame = 4,
TS_WindowFlagResize = 8,
TS_WindowFlagMinimize = 16,
TS_WindowFlagMaximize = 32,
TS_WindowFlagTransient = 64,
TS_WindowFlagFullscreen = 128,
TS_WindowFlagTransparent = 256,
TS_WindowFlagFileDropped = 512,
TS_WindowFlagMultisample2 = 1024,
TS_WindowFlagMultisample4 = 2048,
TS_WindowFlagMultisample8 = 4096,
TS_WindowFlagVerticalSync = 8192,
TS_WindowFlagColorRGBAu8ns = 16384,
TS_WindowFlagColorRGBu10Au2n = 32768,
TS_WindowFlagColorRGBAf16 = 65536,
TS_WindowFlagMultisample = 7168,
TS_WindowDefaultFlags = 59,
TS_WindowNumFlags = 17,
TS_WindowFlags_Maxi32 = 0x7fffffff,
} TS_WindowFlags;
if(!tsWindow_create_cSWF(window, title, TS_WindowDefaultFlags | TS_WindowFlagVerticalSync) || !tsWindow_setHidden(window, 0)) return 1; |
The last 4 could just be Except for the last one, of course... it's every bit except the sign bit. |
But this is not my code, this is a code from C library that I must accept in my V program. I can't change it to make it compatible with current V things |
The code isn't as clear as it could be, but the values are ORed values of the flags. For example, the last few examples could be expressed more clearly as: TS_WindowNumFlags = TS_WindowFlagTitle | TS_WindowFlagMinimize; // 17
TS_WindowDefaultFlags = TS_WindowFlagTitle | TS_WindowFlagClose | TS_WindowFlagResize | TS_WindowFlagMinimize | TS_WindowFlagMaximize; // 59
TS_WindowFlagMultisample = TS_WindowFlagMultisample2 | TS_WindowFlagMultisample4 | TS_WindowFlagMultisample8; // 7168 The following code works fine (as of V 0.4.5 a1d4712): module main
enum WindowFlags as u32 {
@none = 0
title = 1
close = 2
frame = 4
resize = 8
minimize = 16
maximize = 32
transient = 64
fullscreen = 128
transparent = 256
filedropped = 512
multisample2 = 1024
multisample4 = 2048
multisample8 = 4096
verticalsync = 8192
colorrgbau8ns = 16384
colorrgbu10au2n = 32768
colorrgbaf16 = 65536
numflags = 17
defaultflags = 59
multisample = 7168
}
fn main() {
println('numflags: ${int(WindowFlags.numflags)}')
println('defaultflags: ${int(WindowFlags.defaultflags)}')
println('multisample: ${int(WindowFlags.multisample)}')
} Output:
|
Describe the feature
Currently V will output an error if you try to mark enum, that has custom values defined for members, with
[flag]
attribute. V should add support for such a thingUse Case
Usage of C libs that defines flags with custom values
Proposed Solution
No response
Other Information
No response
Acknowledgements
Version used
V 0.4.2
Environment details (OS name and version, etc.)
Not related
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: