> am I missing something?
yes, you're missing one small thing :). Let's look at the definition of
Icallback:
Icallback* = proc (arg: PtrIhandle): cint {.cdecl.}
Run
See the {.cdecl.}, it defines a type of function pointer, with the calling
definition set to cdecl. I don't know how familiar you are with these kind of
things, but basically each procedure/function(in all compiled languages) has a
set calling convention, which specifies how in which processor registers/where
on the stack arguments and return values are passed when calling it. By default
the calling convention of Nim procs is set to nimcall and the compiler applies
exactly that kind of behaviour you described, so actually none of the two
possible overloads match the required type.
Though that leaves one things open: what's about "workaround" you presented.
The reason for this lies in the fact that you used cast. In Nim cast[T]() means
interpret the given data as if it was of type T, completely breaking all safety
measures, it's not needed in this situation. And that explains why it can't
decide which overload to use, because it has no expectations. E.g. this would
compile as well:
setCallback("ACTION", cast[Icallback](42))
Run
And in this case you forcefully convert a proc with the nimcall calling
convention into a cdecl, which obviously goes wrong, since a call to a nimcall
proc could be setup in a completely different way than a cdecl proc call, you
don't know.