Proc types are {.closure.} by default i.e. fat pointer. You want {.cdecl.} instead:
type:
VSAPI* {.importc: "struct VSAPI", header: headerVapourSynth, bycopy.} = object
createCore*: proc(threads:cint):ptr VSCore {.cdecl.}
....
Also as long as you exactly match the struct layout to that of C, you don't need importc and header pragmas for the type, and thus don't depend on the headers at all.Thanks @yglukhov.
The reason why I am playing with VapoursSynth is because I already wrapped it in Julia.
More questions, it is not clear to me if I should define the functions as types (like nimterop does):
type
VSGetVapourSynthAPI* {.impVapourSynth.} = proc(version: cint): VSAPI {.cdecl.}
or like in most examples:
proc VSGetVapourSynthAPI*(version: cint): VSAPI {.impVapourSynth, cdecl.}
What is the difference?
Good progress. It looks like the wrapper works fine now:
$ ./ex01 ptr 0x557ede9361a8 --> [versionString = 0x7f0e3ea18860"VapourSynth Video Processing Library\10" "Copyright (c) 2012-2019 Fredrik Mellbin\10" "Core R48\10" "API R3.6\10" "Options: -\10" "", core = 48, api = 196614, numThreads = 8, maxFramebufferSize = 4294967296, usedFramebufferSize = 0]
Still some work to do.