Hey guys, I've just finished refactoring my C/C++ interop module: https://github.com/n0bra1n3r/cinterop. I started writing it a couple of years ago after stumbling upon nimline, which was its primary inspiration.
I haven't got a chance to upload it as a nimble package yet, but will probably do so soon.
I've used this module to successfully interop with the following C/C++ libraries that I use in my game engine so far:
This interop library would probably be useful to someone who uses similar libraries.
I am playing with it, and it feels really good.
Thanks a lot.
For libraries with lots of functions that don't hang off of classes, this could also be useful. Here is what I did for GLFW:
# glfw3.nim
csource &"{GLFW}/glfw3.h": # header file
type CGLFW* {.cgen:"(GLFW_$1)".} = object of CEnum
type cglfw* {.cgen:"(glfw$1(@))".} = object of CClass
# canvas.nim
...
cauto^cglfw.GetMouseButton(self.window, button) == cauto^CGLFW.PRESS
# generates something like `glfwGetMouseButton(self.window, button) == GLFW_PRESS`
...
What I did here is create a "namespace type" in Nim that is not visible in C++. I used Nim's importcpp under the hood to tell the compiler (via my cgen pragma) how cglfw.field and CGLFW.FIELD should be generated.Hi, yes I can interface with it now, with almost zero effort. DiligentEngine was basically the whole reason I wrote this library; it was extremely difficult to write a wrapper for due to the sheer number of classes, enums, and dependencies. And I couldn't figure out how to do it with the existing wrapper generators without spending too much time.
Unfortunately I haven't had a chance to opensource other parts of my game engine yet. cinterop is basically the first component of the whole thing; I'll slowly refactor and release the other parts as I go.
I can give examples of how I use cinterop to interface with the different libraries over on the github though, if you want to try out using it.