Yaroslav Kavenchuk wrote:
>How define unnamed call-in function and determine it address?
I suggest you look at tests/ffi.tst again:
> (defun callback (x) (/ x 3))
> (with-c-var (x '(c-function (:arguments (x uint))
(:language :stdc)) #'callback) x)
;; or use #'(lambda ...) here instead
> (setq foo *)
> (funcall foo 123)
> (funcall foo 2)
*** - 2/3 cannot be converted to the foreign type UINT
The following restarts are available:
ABORT :R1 ABORT
> (foreign-address foo)
[...]> (foreign-free foo)
#<INVALID FOREIGN-FUNCTION #x081C3EE0>
Arguably, the current ffi:foreign-function constructor could be enhanced to accept a Lisp function objects as input and create a foreign-function object from it. That seems to make some sense.
Note that when some call-out function has as :argument (c-function ...), a Lisp function is automatically converted to a foreign function pointer that is then passed to the foreign function. But then, you don't get to see its address.
>How call c-function to its address (without name)?
Use funcall on the #<foreign-function #> object or what do you mean?
>>How call c-function to its address (without name)?
> Use funcall on the #<foreign-function #> object or what do you mean?
Now nothing :)
WBR, Yaroslav Kavenchuk.