Why does it does not work?

oleg harput olegharput at gmail.com
Thu Jun 8 14:05:29 UTC 2023


Hi. I want to use the following C function:

;; void ClearBackground(Color color);

Color is C Struct:

;; typedef struct Color {
;;     unsigned char r;        // Color red value
;;     unsigned char g;        // Color green value
;;     unsigned char b;        // Color blue value
;;     unsigned char a;        // Color alpha value
;; } Color;

So I wrote:

(cffi:defcstruct %color
  (r :uint8)
  (g :uint8)
  (b :uint8)
  (a :uint8))

(defvar *%lightgray* (cffi:foreign-alloc '(:struct %color)))

(cffi:with-foreign-slots ((r g b a) *%lightgray* (:struct %color))
  (setf (cffi:foreign-slot-value *%lightgray* '(:struct %color) 'r) 200)
  (setf (cffi:foreign-slot-value *%lightgray* '(:struct %color) 'g) 200)
  (setf (cffi:foreign-slot-value *%lightgray* '(:struct %color) 'b) 200)
  (setf (cffi:foreign-slot-value *%lightgray* '(:struct %color) 'a) 255)
  (format t "~s ~s ~s ~s" r g b a))

;; void ClearBackground(Color color);
(cffi:defcfun ("ClearBackground" %clear-background) :void
  (color (:struct %color)))

(defun clear-background (color)
  (%clear-background color))

But when i run

(clear-background *%lightgray*)

That does not work, I have already added my .asd file ":cffi-libffi" as
dependency.

What is the problem? If this issue has no solution, is there an alternate
way?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20230608/e2a95cf8/attachment.html>


More information about the cffi-devel mailing list