[Top][All Lists]

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

Re: ffi for glutInit

From: Mark H Weaver
Subject: Re: ffi for glutInit
Date: Thu, 26 Jul 2012 12:39:25 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0

Sorry, the indentation of my example code got messed up by tabs.
Here it is again:

  (use-modules (system foreign))

  (define libglut-obj (dynamic-link "libglut"))

  ;; (glut-init args), where args is the complete list of command
  ;; arguments (starting with the program name), calls glutInit and
  ;; returns the (possibly) modified list of arguments.
  (define glut-init
    (let ((foo-init-raw (pointer->procedure
                         (dynamic-func "glutInit" libglut-obj)
                         (list '* '*)))
          (saved-c-strings '()))
      (lambda (args)
        (let* ((num-args (length args))
               (c-strings (map string->pointer args))
               (argcp (make-c-struct (list int)
                                     (list num-args)))
               (argv (make-c-struct (make-list (+ 1 num-args) '*)
                                    (append c-strings
                                            (list %null-pointer)))))
          (set! saved-c-strings (append c-strings saved-c-strings))
          (foo-init-raw argcp argv)
          (let ((argc (car (parse-c-struct argcp (list int)))))
            (map pointer->string
                 (parse-c-struct argv
                                 (make-list argc '*))))))))

  ;; Example usage
  (set-program-arguments (glut-init (program-arguments)))


reply via email to

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