Hi All,
Is there a namespace I should implement in Raylib? For example, I cannot compile without writing Colors at the beginning of the colors: Colors.GRAY
SDB@79
Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 28, 2022 Colors in Raylib | ||||
---|---|---|---|---|
| ||||
Hi All, Is there a namespace I should implement in Raylib? For example, I cannot compile without writing Colors at the beginning of the colors: SDB@79 |
February 28, 2022 Re: Colors in Raylib | ||||
---|---|---|---|---|
| ||||
Posted in reply to Salih Dincer | On Monday, 28 February 2022 at 11:48:59 UTC, Salih Dincer wrote: >Hi All, Is there a namespace I should implement in Raylib? For example, I cannot compile without writing Colors at the beginning of the colors: SDB@79 Assuming you mean the raylib-d binding, it implements the values as a named enum, so the https://dlang.org/spec/enum.html#named_enums If you have a situation where you need to type it multiple times in consecutive code lines, you can use
Then you can drop the namespace and just used the values. Very useful for switches:
You can also generate aliases, so that e.g.,
Then you can mixin aliases for any named enum members you'd like:
|
February 28, 2022 Re: Colors in Raylib | ||||
---|---|---|---|---|
| ||||
Posted in reply to Salih Dincer | On Monday, 28 February 2022 at 11:48:59 UTC, Salih Dincer wrote: >Is there a namespace I should implement in Raylib? For example, I cannot compile without writing Colors at the beginning of the colors: When writing C bindings, you may refer to this: This keeps example code working. |
February 28, 2022 Re: Colors in Raylib | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On Monday, 28 February 2022 at 12:18:37 UTC, Mike Parker wrote: >
Then you can mixin aliases for any named enum members you'd like:
It definitely works, thank you. |
February 28, 2022 Re: Colors in Raylib | ||||
---|---|---|---|---|
| ||||
Posted in reply to Salih Dincer | On 2/28/22 6:48 AM, Salih Dincer wrote: >Hi All, Is there a namespace I should implement in Raylib? For example, I cannot compile without writing Colors at the beginning of the colors: SDB@79 If you refer to raylib-d, that's how it was since I've ever used it. The original C code uses #defines for all the colors. It's an interesting incompatibility issue:
I think this is the only reason the colors are not an enum in the C code in the first place. One way to fix this would be to just use individual enums to the raylib-d binding. I think it might have been this way originally. I'm hesitant to change it, but I might define both at some point. In general, the raylib enumerations are overly verbose for D, e.g. -Steve |
March 01, 2022 Re: Colors in Raylib | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 1 March 2022 at 02:42:52 UTC, Steven Schveighoffer wrote: >On 2/28/22 6:48 AM, Salih Dincer wrote: >In general, the raylib enumerations are overly verbose for D, e.g. In Derelict, I exclusively used anonymous enums with an alias to the base type like Guillaume noted above. When I did bindbc-sdl, I decided to go with named enums + the template I pasted above---I put the mixin at the bottom of each enum declaration. Though I do use anonymous enums now for any that are intended to be used as bit flags. The mixin approach allows you to keep the stronger typing of named enums and still maintain one-to-one compatibility with the with the C source if both are important to you. I'm ambivalent about it now. |
March 01, 2022 Re: Colors in Raylib | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | If the type is |
March 01, 2022 Re: Colors in Raylib | ||||
---|---|---|---|---|
| ||||
Posted in reply to meta | On 3/1/22 7:22 AM, meta wrote: >If the type is The problem is how the original source works. The only way to define a manifest constant for a struct instance in C is to #define it. So I'm sure that if raylib could put that inside the What a D binding should do is exactly what Mike said -- provide a complete binding as expected, and then add machine-generated nicer APIs. I actually have an open issue, in case anyone is interested in working on it: https://github.com/schveiguy/raylib-d/issues/8 -Steve |
March 01, 2022 Re: Colors in Raylib | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 1 March 2022 at 12:29:56 UTC, Steven Schveighoffer wrote: >On 3/1/22 7:22 AM, meta wrote: >If the type is The problem is how the original source works. The only way to define a manifest constant for a struct instance in C is to #define it. So I'm sure that if raylib could put that inside the What a D binding should do is exactly what Mike said -- provide a complete binding as expected, and then add machine-generated nicer APIs. I actually have an open issue, in case anyone is interested in working on it: https://github.com/schveiguy/raylib-d/issues/8 -Steve Oh I was talking with regard to D's enum, not about the binding, allowing it via D, would make interfacing with C code easier
|