[plt-scheme] FFI, argc and argv

From: Eli Barzilay (eli at barzilay.org)
Date: Sun May 6 15:18:29 EDT 2007

On May  6, Paulo J. Matos wrote:
> On 5/6/07, Eli Barzilay <eli at barzilay.org> wrote:
> > On May  6, Paulo J. Matos wrote:
> > >
> > > Two issues come to my mind:
> > > - command-line-arguments do not provide, afaik, argv[0].
> >
> > No, that's the reason for `-C'.
> 
> What do you mean by this? (I'm probably missing something, is that a
> flag?)

Yes.  Try this:

  #!/bin/sh
  #|
  exec mzscheme -C "$0" "$@"
  |#
  (define (main args)
    (printf "args = ~s\n" args))



> > You don't even need to convert the vector to a list because
> > _vector does that:
> >
> >   (define main
> >     (get-ffi-obj "main" "x.so"
> >       (_fun (v) :: (_int = (vector-length v)) ((_vector i _string) = v)
> >             -> _void)))
> >   (main '#("j" "k" "l"))
> 
> If I pass (command-line-arguments) as the vector and the function
> expects argv[0] to be name of the program, "j" will have to be it,
> right?

Yes.  (I'm not sure now what was your original question about: the
foreign interface, or the command line arguments.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.