The manpage for libffi features an example that, essentially, requires a pointer to the function (in the examples case, puts
).
However, what do I do if I only know the name of the function, but don't actually have a pointer (which would usually happen if ffi is used in, say, dynamic programming languages)?
Say, I want to do something like this (pseudocode):
cif = null
s = "Hello World"
args = []
values = []
args[0] = ffi.type_pointer
values[0] = address_of(s)
if(ffi.prepare(cif, ffi.DEFAULT_ABI, ffi.type_uint, args)):
ffi.call(cif, "puts", values)
In short, i want to have libffi dynamically look up the function (if that's supported by ffi in the first place) similar to dlfcn/LoadLibrary, and then call it with the supplied FFI CIF types.
Is such a thing possible with libffi? What would a simple example look like?