unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: guile-devel@gnu.org
Subject: Re: ffi for glutInit
Date: Thu, 26 Jul 2012 12:39:25 -0400	[thread overview]
Message-ID: <501172BD.80000@netris.org> (raw)
In-Reply-To: <50117174.6040104@netris.org>

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
                          void
                          (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)))

      Mark




  reply	other threads:[~2012-07-26 16:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-25 22:19 ffi for glutInit Aleix Conchillo Flaqué
2012-07-26  2:30 ` Nala Ginrut
2012-07-26 15:46   ` Aleix Conchillo Flaqué
2012-07-26 16:33 ` Mark H Weaver
2012-07-26 16:39   ` Mark H Weaver [this message]
2012-07-26 18:07     ` Nala Ginrut
2012-08-04 16:19   ` Aleix Conchillo Flaqué
2013-01-21 12:04 ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=501172BD.80000@netris.org \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).