I'd like to call a function that calls a c function, but I want to be able to swap out the actual C function
function Ccall(fn)
... more code 1 ...
ccall((fn, libc), Int32, ())
... more code 2 ...
end
where the more code part is always the same but fn can change.
For a simple example, I try to call this Ccall function
f = "clock" |> Symbol
Ccall(f)
but I get an error message. Also tried
function Ccall(fn)
... more code 1 ...
ccall(fn, Int32, ())
... more code 2 ...
end
with
const f = ("clock" |> Symbol, "libc")
Ccall(f)
but no luck, f is not a constant expression, what it should be, just because I put a const in front.
Is there a way of ccall-ing with the above genericity? If so, how?
ccall requires an expression, not a value---it's a little bit like a macro in that regard. You can generate the appropriate expressions (see the HDF5.jl package for one example), but your best bet is probably to create one wrapper-function per C function as Gnimuc Key suggested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With