Now, if I have a pointer to a function defined, how can I pass a
function to the struct. For example, can I use a defun?
(defun test-c (a-the-int)
(print "--X"))
(def-c-struct test-pointer-function
(a int)
(b (c-function
(:arguments (v int))))
)
;;;
;;; #S(WIDGET-TOOLKIT::FOO :A 5)
;;;
(defun test-s2 ()
(let ((ab (make-test-pointer-function :a 1 :b (test-c 1))))
(print px)
(print ab)
))
;;;
From: Edi Weitz
Subject: Re: Another question, pass a function to the function pointer
Date:
Message-ID: <uekht4w0q.fsf@agharta.de>
On 13 Dec 2004 15:19:36 -0800, "ramza2" <············@gmail.com> wrote:
> Now, if I have a pointer to a function defined, how can I pass a
> function to the struct. For example, can I use a defun?
No. Your Lisp's FFI will have to provide a means to define a
"callback" or "foreign callable." For LispWorks, e.g., this looks like
so:
<http://www.lispworks.com/reference/lw44/FLI/html/fli-70.htm>
To pass a pointer to this function to C you'll have to use a technique
similar to this one
<http://www1.xanalys.com/support/lisp/kbase.nsf/51fe6e1cdfe748a180256639005a2ba9/404d1bad7fe771f3802568c400540b50?OpenDocument>
unless your Lisp image is somehow embedded (maybe as a shared library)
in the calling C application.
For CLISP specifics your best bet is to ask on the CLISP mailing
list. (Or read their docs. AFAIK their FFI is quite new, I don't know
if it's fully documented yet.)
HTH,
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
Edi Weitz wrote:
> For CLISP specifics your best bet is to ask on the CLISP mailing
> list. (Or read their docs. AFAIK their FFI is quite new, I don't know
> if it's fully documented yet.)
Their FFI looks *really* nice, but when I tried to use it (going over all
the docs, even) I couldn't make heads nor tails of it. If I knew C a lot
better, maybe I would understand it. The docs were fairly rudimentary, and
perhaps sufficient for someone that already knows what they're doing. YMMV.
Chris Capel
I think I figured it out:
My goal is to create a struct that has a pointer to a function:
(def-c-struct test-pointer-function
(a int)
(b (ffi:c-function (:arguments (number ffi:int))
(:return-type ffi:int)
(:language :stdc))
))
here is a struct witha member b ... that is a pointer to a function, a
function with an int, no return.
here is the function that I want pointed to:
(defun test-s2 ()
(let ((pd
(make-test-pointer-function :a #'test-c))
)
(print pd)
))
(defun test-c (a-the-int)
(print "--X")
a-the-int)
Now I just have to figure out how to call that from the struct probably
not that hard
On another note, I am really loving this stuff, lisp, I really regret
having worked with those other langauges so much
...
....
...weep...
Chris Capel wrote:
> Edi Weitz wrote:
>
>
>>For CLISP specifics your best bet is to ask on the CLISP mailing
>>list. (Or read their docs. AFAIK their FFI is quite new, I don't know
>>if it's fully documented yet.)
>
>
> Their FFI looks *really* nice,
yep. killer.
> but when I tried to use it (going over all
> the docs, even) I couldn't make heads nor tails of it. If I knew C a lot
> better, maybe I would understand it.
yep. for this, knowing C matters more than knowing Lisp.
> The docs were fairly rudimentary, and
> perhaps sufficient for someone that already knows what they're doing. YMMV.
Working examples rule. Run, do not walk, to Vasilis's original cells-gtk
which is pure CLisp FFI:
http://common-lisp.net/cgi-bin/viewcvs.cgi/clisp-cgtk/?cvsroot=cells-gtk
Only a kazillion examples in there. Vasilis really exhausted all the
permutations in GUI development and along the way tapped the power of
the CLisp FFI pretty exhaustively. Anonymous functions as callbacks!
(Which Burdick mentioned he was doing for SBCL a ways back...). I am
generally pretty high on AllegroCL, but it looks like they have some
catching up to do.
kt
--
Cells? Cello? Celtik?: http://www.common-lisp.net/project/cells/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film