Lisp HUG Maillist Archive

Providing argc and argv to a foreign function

I wish to call a foreign function whose first two arguments are argc
and argv. The foreign function definition is as follows:

(fli:define-foreign-function (|fl_initialize| "fl_initialize" :source)
                             ((|na| (:pointer :int))
                              (|arg| (:c-array (:pointer :char)))
                              (|appclass| (:pointer (:const :char)))
                              (|appopt| (:pointer |XrmOptionDescRec|))
                              (|nappopt| :int))
                             :result-type
                             (:pointer |Display|)
                             :language
                             :ansi-c)

|na| corresponds to argc which is defined as (:pointer :int). How do I
get argc in LispWorks?

|arg| corresponds to argv. How do I get that?
|appclass| is usually given a string as value. What should I write in
           the call to |fl_initialize|?
|appopt| is usually given in C as NULL. Do I provide "nil" for that?
|nappopt| is easy. It's zero (0).

Any help would be appreciated.
-- 
Dr Sian Mountbatten
http://www.poenikatu.co.uk/
Associate member of the FSF no. 10888
Asocia membro de la Libera Programara Fonduso n-ro 10888

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: Providing argc and argv to a foreign function

On 05/09/14 16:58, Sian Mountbatten wrote:
> 
> I wish to call a foreign function whose first two arguments are argc
> and argv. The foreign function definition is as follows:
> 
> (fli:define-foreign-function (|fl_initialize| "fl_initialize" :source)
>                              ((|na| (:pointer :int))
>                               (|arg| (:c-array (:pointer :char)))
>                               (|appclass| (:pointer (:const :char)))
>                               (|appopt| (:pointer |XrmOptionDescRec|))
>                               (|nappopt| :int))
>                              :result-type
>                              (:pointer |Display|)
>                              :language
>                              :ansi-c)
> 
> |na| corresponds to argc which is defined as (:pointer :int). How do I
> get argc in LispWorks?
> 
> |arg| corresponds to argv. How do I get that?

See sys:*line-arguments-list* and section 4.2.5 of the FLI reference
manual ("Calling a C function that takes an array of strings").

> |appclass| is usually given a string as value. What should I write in
>            the call to |fl_initialize|?

You could use the following in the foreign function definition:

(|appclass| (:reference-pass
              (:ef-mb-string :null-terminated-p t)))

and then pass a lisp string for that argument.

> |appopt| is usually given in C as NULL. Do I provide "nil" for that?

Pretty sure that nil provided as the value for a :pointer argument is
converted to a null pointer.  You can also use fli:*null-pointer*.

> |nappopt| is easy. It's zero (0).

If it's always 0, you could use the following definition in place of
that argument:

(:constant 0 :int)

See also the :lambda-list arg to fli:define-foreign-function.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:34 UTC