From: yong
Subject: Functions in dynamic library
Date: 
Message-ID: <erpm1v$8cq$1@news.yaako.com>
Could somebody tell me how can I call functions that in a dynamic library?

I'm using clisp under linux.

Thanks.

From: Lars Rune Nøstdal
Subject: Re: Functions in dynamic library
Date: 
Message-ID: <pan.2007.02.24.15.48.33.117604@gmail.com>
On Sat, 24 Feb 2007 23:36:45 +0800, yong wrote:

> Could somebody tell me how can I call functions that in a dynamic library?
> 
> I'm using clisp under linux.
> 
> Thanks.


Use CFFI ( http://common-lisp.net/project/cffi/ ) for this:

cl-user> (asdf:operate 'asdf:load-op :cffi)


First load a library (libm contains functions common math stuff):

  cl-user> (cffi:load-foreign-library "/usr/lib/libm.so")


Then you can call functions in it. For instance:

  cl-user> (cffi:foreign-funcall "cos" :double pi :double)
  -1.0d0

-- 
Lars Rune Nøstdal
http://nostdal.org/
From: yong
Subject: Re: Functions in dynamic library
Date: 
Message-ID: <errqcj$h6$1@news.yaako.com>
Lars Rune Nøstdal wrote:
> On Sat, 24 Feb 2007 23:36:45 +0800, yong wrote:
> 
>> Could somebody tell me how can I call functions that in a dynamic library?
>>
>> I'm using clisp under linux.
>>
>> Thanks.
> 
> 
> Use CFFI ( http://common-lisp.net/project/cffi/ ) for this:
> 
> cl-user> (asdf:operate 'asdf:load-op :cffi)
> 
> 
> First load a library (libm contains functions common math stuff):
> 
>   cl-user> (cffi:load-foreign-library "/usr/lib/libm.so")
> 
> 
> Then you can call functions in it. For instance:
> 
>   cl-user> (cffi:foreign-funcall "cos" :double pi :double)
>   -1.0d0
> 

Thanks a lot :)
From: ·············@gmail.com
Subject: Re: Functions in dynamic library
Date: 
Message-ID: <1172431200.059592.150800@v33g2000cwv.googlegroups.com>
On Feb 24, 10:36 am, yong <··········@enorth.com.cn> wrote:
> Could somebody tell me how can I call functions that in a dynamic library?
>
> I'm using clisp under linux.
>
> Thanks.
Using clisp only .. without asdf packages:

(defpackage :curses_ffi
  (:nicknames :ncurses)
  (:use :common-lisp :ffi :system :ext)
  (:export initscr  refresh endwin getch printw simple-test))

(in-package :ncurses)

(default-foreign-language :stdc)

(defmacro cfunc (lisp-name c-name &key arguments return-type)
  `(def-call-out ,lisp-name
      (:name ,c-name)
      (:library "/usr/lib/libncurses.so")
      (:arguments ,@arguments)
      ,@(if return-type (list `(:return-type ,return-type)))))

(defmacro cvar (name)
  `(def-c-var ,name (:type c-pointer) (:library "/usr/lib/
libncurses.so")))

(cfunc initscr "initscr")

(cfunc refresh "refresh")

(cfunc endwin "endwin")

(cfunc getch "getch" :return-type int)

(cfunc printw "printw" :arguments ((message c-string)))

;; simple test usage --  further information > man ncurses
(defun simple-test ()
  (initscr)
  (printw "Hello World")
  (refresh)
  (getch)
  (endwin))

(ncurses::simple-test)