cimnodes icon indicating copy to clipboard operation
cimnodes copied to clipboard

Why there is no ImNodesContext type in structs_and_enums.json?

Open gucio321 opened this issue 2 years ago • 11 comments

gucio321 avatar Sep 03 '23 09:09 gucio321

after a quick look at code I suppose that imnodes_internal.h support is missing

gucio321 avatar Sep 03 '23 10:09 gucio321

Yes

sonoro1234 avatar Sep 03 '23 11:09 sonoro1234

Ok, are there any plans to fix this? I'd love to contribute but unfortunately I have absolutely no experience with lua.

gucio321 avatar Sep 08 '23 12:09 gucio321

It is no fix but enhancement. I can check it but imnodes seems abandoned.

Which is the use of ImNodesContext that you need? With imnodes.h you have the declaration as an opaque type.

sonoro1234 avatar Sep 08 '23 12:09 sonoro1234

We need this structure to be in json file in cimgui-go, because we can't generate wrapper for functions like CreateContext -essential to use the library

gucio321 avatar Sep 08 '23 15:09 gucio321

As CreateContext is returning a pointer to ImNodesContext (ImNodesContext *) you should not need the detailed structure of ImNodesContext. It could even be defined as a void *. Whatever is returned by imnodes_CreateContext can be used in imnodes_SetCurrentContext or imnodes_DestroyContext without knowing the specific ImNodesContext structure.

An opaque type is a type which is exposed in APIs via a pointer but never concretely defined.

In typedefs_dict.json you will see "ImGuiContext": "struct ImGuiContext", which in C is typedef struct ImNodesContext ImNodesContext; where ImNodesContext is an opaque struct. You cant use ImNodesContext but you can use ImNodesContext *

sonoro1234 avatar Sep 08 '23 16:09 sonoro1234

yes, but there are three problems:

  • we generate equivalents of all structs in go (in case someone needs to know some value stored inside them)
  • also, our current implementation we rely only on structs_and_enums.json
  • we can't use void* (which is unsafe.Pointer in go) because... well Go does not have usable integration between go and C for this type :smile:

It'd be the best solution for us (if possible) to implement solution already present in cimgui - add cimnodes_internal to generator

gucio321 avatar Sep 08 '23 16:09 gucio321

If you know any GLFW wrapping in go, you could look how is handled in:

GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL);

https://www.glfw.org/docs/3.3/window_guide.html#window_object

https://github.com/go-gl/glfw is one of them.

sonoro1234 avatar Sep 08 '23 18:09 sonoro1234

Well, i Knorr about this method am theoretically i could do it this way, but (as mentioned above) handling pointers is not the reason why i need nodesContext in structs_and_enums.json We also need to generate setters/getters for fields of this structure so that our users could obtain some days about this context.

gucio321 avatar Sep 08 '23 20:09 gucio321

generate setters/getters for fields of this structure

When a structure is opaque it is usually for avoiding this. Which fields would be interesting to get/set and what for?

sonoro1234 avatar Sep 09 '23 08:09 sonoro1234

When a structure is opaque it is usually for avoiding this.

I see. However cimgui allows generating these types when internal specified... What we need is a compatibility between cimgui and other wrappers because so that our generator could work as expected. Also I can't say which exactly field of ImNodesContext our users may need, however because of GO's types privacy, they wouldn't be able to access these fields anyhow (when they theoritically could if they used C++ code by #include "imnodes_internal.h")

gucio321 avatar Sep 11 '23 12:09 gucio321