gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gcl-devel] Foreign Function Interface, something similar to clisp ffi?


From: Camilo Olarte
Subject: [Gcl-devel] Foreign Function Interface, something similar to clisp ffi?
Date: Sat, 8 Jan 2005 02:50:43 -0500
User-agent: Internet Messaging Program (IMP) 3.1

Hello list,

I was studying the way to interface foreign functions from common lisp, until
now i can only do it with clisp implementation, i was wondering how can i do the
same in gcl.

the idea is to access functions from a shared library in the example's case it
is the libncurses library.

I am aware of the defentry and c-lines functions in gcl , but  until now the
only clear thing i understand : is that with defentry you can access functions
to linked libraries that were chosen in time of compilation of the gcl
implementation. Also c-lines would let me include a chunk of c code.
The idea i repeat is to access a shared library, in the documentation something
is said about faslinks... what i understand is that it only works in BSD
machines...not linux (by the way i am testing this code in linux machine RH9 and
debian)

So back to the question : is there some gcl code equivalent to the cliso one
below???
can i access a shared c library (*.so) from gcl implementation without having to
recompile the gcl implementation to make this links??

---- start lisp code : clisp 2.33 implementation  -----
(use-package 'ffi)
(default-foreign-language :stdc)

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

; Define the external functions
(cfunc initscr "initscr")
(cfunc refresh "refresh")
(cfunc getch "getch")
(cfunc printw "printw" :arguments ((message c-string)))
(cfunc endwin "endwin")

; use foreign functions from clisp
(initscr)
(printw (format nil "Hello ~2%World"))
(refresh)
(getch)
(endwin)
---- end lisp code -----

Camilo Olarte






Telesat, más fácil...más Internet.
http://www.telesat.com.co/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]