[Top][All Lists]

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

[Chicken-users] How to provide csc/csi bindings for a C library?

From: Sven Hartrumpf
Subject: [Chicken-users] How to provide csc/csi bindings for a C library?
Date: Mon, 21 Oct 2002 18:33:19 +0200 (CEST)

Hi all.

I have a set of bindings (wrapper functions) for a C library (SCOP).
I want to use it mainly in several csc-compiled Scheme programs, but
maybe also in csi.
My current try (BTW: the transformation from bigloo was straightforward
so far :-) ) is at the end of this mail.

I compile the Scheme file to a shared object file named
> csc -s scop_chicken.scm

The original C library is libscop.a (I can produce if this is
really needed).

Now, what is the best (i.e. clean, easy, and efficient) way
to use the bindings in csc?

And what about csi?

Sorry for my ignorance, but that combination of chicken and C is new to me.


; scop_chicken.scm
; Scheme binding for SCOP 1.1, chicken version
; Sven Hartrumpf, 2002-10-21

; C functions from SCOP:

(define c_close (foreign-lambda int "close" int))
(define c_scop_clear (foreign-lambda void "scop_clear" int c-string))
(define c_scop_emit (foreign-lambda int "scop_emit" int c-string int))
;(c_free::void (voidp) "free") ; not needed
(define c_scop_get_message (foreign-lambda c-string "scop_get_message" int 
(pointer int)))
(define c_scop_listen (foreign-lambda void "scop_listen" int c-string int))
(define c_scop_open (foreign-lambda int "scop_open" c-string c-string int))
(define c_scop_query (foreign-lambda int "scop_query" int c-string))
(define c_scop_reconfigure (foreign-lambda void "scop_reconfigure" int))
(define c_scop_rpc (foreign-lambda c-string "scop_rpc" int c-string c-string))
(define c_scop_send_message (foreign-lambda int "scop_send_message" int 
c-string c-string int))
(define c_scop_send_reply (foreign-lambda int "scop_send_reply" int c-string))
(define c_scop_set_log (foreign-lambda void "scop_set_log" int int))
(define c_scop_set_source_hint (foreign-lambda void "scop_set_source_hint" int 
(define c_scop_terminate (foreign-lambda void "scop_terminate" int))

; Scheme counter parts of SCOP functions, API level 1:

(define scop-clear (lambda (sock endpoint)
  (c_scop_clear sock endpoint)

(define scop-close (lambda (sock)
  (c_close sock)))

(define scop-emit (lambda (sock message . verify0)
  (let ((verify (if (pair? verify0)
                  (car verify0)
    (c_scop_emit sock message verify))))

;(define scop-free (lambda (ptr) ; not needed
;  (c_free ptr)))

(define scop-get-message (lambda (sock . rpc-flag)
  (if (null? rpc-flag)
    (c_scop_get_message sock (null-pointer)) ; difference to scop_bigloo.scm
    (c_scop_get_message sock (null-pointer)) ; difference to scop_bigloo.scm 
ZZZ use address of integer rpc-flag instead of 0

(define scop-listen (lambda (sock interest . unique0)
  (let ((unique (if (pair? unique0)
                  (car unique0)
    (c_scop_listen sock interest unique)

(define scop-open (lambda (remote-hostname name . unique0)
  (let ((unique (if (pair? unique0)
                  (car unique0)
    (c_scop_open remote-hostname name unique))))

(define scop-query (lambda (sock endpoint)
  (c_scop_query sock endpoint)))

(define scop-reconfigure (lambda (sock)
  (c_scop_reconfigure sock)

(define scop-rpc (lambda (sock remote-hostname args)
  (c_scop_rpc sock remote-hostname args)))

(define scop-send-message (lambda (sock endpoint message . verify0)
  (let ((verify (if (pair? verify0)
                  (car verify0)
    (c_scop_send_message sock endpoint message verify))))

(define scop-send-reply (lambda (sock reply)
  (c_scop_send_reply sock reply)))

(define scop-set-log (lambda (sock log-level)
  (c_scop_set_log sock log-level)

(define scop-set-source-hint (lambda (sock endpoint)
  (c_scop_set_source_hint sock endpoint)

(define scop-terminate (lambda (sock)
  (c_scop_terminate sock)

; optional Scheme extensions to SCOP

(include "scopsx.scm")

reply via email to

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