On Sun Dec 14, 2025 at 11:50 AM CET, Diogo wrote: > On Sat, Dec 13, 2025 at 03:41:57PM +0100, Felix Winkelmann wrote: > > Thanks for that. I will give a try right away. It is possible to "derefence" > the impl wrapper so that I could achieve this selection of behavior from the > chicken side?
There is no reliable way to extract a raw callable function pointer from a closure, since there is context information the code needs access to. > > To exemplify the whole issue, I am testing a crunch procedure > > scan-matrix(m, read-col) > > Where m is "matrix" object in crunch that represents a keyboard and "real-col" > is a procedure which reads the state of one keyboard column and returns it > encoded in some byte. When running this on a microcontroller, I want to use > real-col that uses quite platform specific functionality which I cannot > compile > when testing this on the host. On the host, I want to create a "mock" read-col > in crunch, and then use chicken to call scan-matrix with that mock read-col > and > then evaluate the results among other things. > > Do you have another/better suggestion how I could replace the functionality > inside a crunch module that is called from chicken? You can use the normal foreign function interface facilities for callbacks, i.e. "define-external" to define a callback entry-point and "location" to obtain the C function pointer of the entry-point. But I see here that there is no way to parameterize the generated wrapper for crunched procedures (the functionality is there, just not accessible). I will add this. cheers, felix
