So... I'm still struggling with the Webview wrapper for Nim (very, very close to get it right; but a couple of issues still popping up)
So...
Important Note: I'm compiling as C++ with VCC/cl.exe. (the exact same thing compiles fine & works flawlessly for Clang/macOS & GCC/Linux)
Here's my type definition (at least the relevant ones):
type
Webview* {.importc: "webview_t".} = pointer
WebviewCallback* = proc (seq: cstring, req: cstring, arg: pointer) {.cdecl.}
Here's the function import:
proc webview_bind*(w: Webview, name: cstring, cb: WebviewCallback, arg: pointer) {.importc.}
Here's how the exact same thing is declared in webview.h (C/C++):
WEBVIEW_API void webview_bind(webview_t w, const char *name,
void (*fn)(const char *seq, const char *req,
void *arg),
void *arg);
And here's the error code I'm getting (from the CI build, since I don't have a Windows machine):
@mhelpers@swebviews.nim.cpp
D:\a\arturo\arturo\.cache\@mhelpers@swebviews.nim.cpp(1286): error C2664: 'void webview_bind(webview_t,const char *,void (__cdecl *)(const char *,const char *,void *),void *)': cannot convert argument 3 from 'tyProc__6j8G629bS5b9a9a48K9cMq8U9aA' to 'void (__cdecl *)(const char *,const char *,void *)'
D:\a\arturo\arturo\.cache\@mhelpers@swebviews.nim.cpp(1286): note: This conversion requires a reinterpret_cast, a C-style cast or parenthesized function-style cast
D:\a\arturo\arturo\src\extras\webview/webview.h(98): note: see declaration of 'webview_bind'
If you ask me (and Clang/GCC), I'm already doing right - and the correspondence between the argument definitions is correct. If you ask VCC/cl, it seems to... disagree.
Any ideas?
OK, I think I've spotted it:
I'm declaring WebviewCallback's seq & req as cstring (which - from what I've seen - means char*), while the actual seq & req are declared as const char*.
Now, let's see how I can get around this...
Attempting this:
type
ccstring {.importc:"const char*".} = cstring
WebviewCallback* = proc (seq: ccstring, req: ccstring, arg: pointer) {.cdecl.}
Again, it has already compiled fine on Mac - let's see what sort of surprise comes up from the Windows build.
Attempting to also change the definition of the passed proc in the caller function (which I previously forgot).
Again, Mac works fine. Waiting for the Windows build...
So... final update: I got it to work.
Apart from the changes mentioned above:
cast[cstring](seq)
Now, my only issue is VCC/cl itself I guess. The linking stage takes ages to complete (~60 minutes compared to 5-6 minutes on Linux/Mac CI builds), but I have no idea why.
I want(ed) to use MINGW, but then the issue is that I get one ton of other unrelated errors (because of the Webview2-related libraries) + I've seen that it's very challenging. So, I decided to abandon the idea and go for VCC.