Is it possible to splat into ccall?

A couple notes and ideas, fwiw

  1. For separating args from varargs, I see appeal in using , but it seems like : would be more ergonomic. Subjective of course. You could use any other operator too, like |, >, etc, or maybe wrap the varargs in their own tuple.
  2. For the method using Pairs like 2=>Cint, it feels a bit backwards; Cint=>2 feels more natural to me. Another idea would be to use Cint: 2, though that’s likely to get pushback as it would entail type piracy, but that could be solved by getting it into Base.
  3. As discussed in this thread, there might be difficulties in getting some programs that use such a generated function to compile statically. That said, ccall already seems to cause trouble for static compilation. I haven’t dug in to understand why.

If we’re willing to diverge from existing semantics a bit more, maybe something like this becomes compelling:

Ccall(Cdouble: :pow, Cdouble: 2, Cdouble: 10)
Ccall(Cint: :printf, Cstring: "%d %f %s\n", (Cint: 1, Cdouble: 2.0, Cstring: "Hello"))

or maybe:

Ccaller(Cdouble, :pow, Cdouble, Cdouble)(2, 10)
Ccaller(Cint, :printf, Cstring, (Cint, Cdouble, Cstring))("%d %f %s\n", (1, 2.0, "Hello"))

Chef’s choice.

1 Like