bottlenoselabs / c2cs

Generate C# bindings from a C header.
MIT License
245 stars 18 forks source link

Invalid code generated for static constants of int enum types #150

Closed shayded-exe closed 10 months ago

shayded-exe commented 1 year ago

Here's an example from raylib:

[CNode(Kind = "MacroObject")]
public static ShaderLocationIndex SHADER_LOC_MAP_DIFFUSE = 15;

This gives the following error:

error CS0266: Cannot implicitly convert type 'int' to 'Raylib_cs.Raylib.MaterialMapIndex'.
An explicit conversion exists (are you missing a cast?)

The constant should either be initialized using the enum name, or the int should be cast.

This is the only error I get trying to generate bindings for raylib.

lithiumtoast commented 1 year ago

An explicit cast would be the correct way go about this. It's a pretty simple fix.

This is the only error I get trying to generate bindings for raylib.

Does Raylib want to automate the bindings?

shayded-exe commented 1 year ago

Does Raylib want to automate the bindings?

What do you mean? I'm just doing this for my own use and learning. It would be cool to have it fully automated.

lithiumtoast commented 10 months ago

fixed in https://github.com/bottlenoselabs/c2cs/pull/157