Lisp HUG Maillist Archive

Defining callback functions with varargs

Hi everyone,

 

currently I’m trying to define a callback function in Lispworks that accepts varargs (as that is the defined interface for the callback), i.e. the defined callback must match the following signature:

 

void myCallback(Component c, myString name, myStatus status, myString category,

 myString message, ....);

 

Defining a similar callback from Lisp for the non-variable arguments is simple, e.g.

 

(fli:define-foreign-callable ("myCallback" :result-type :void :calling-convention :cdecl)

    ((component component-ptr)

     (name (:reference-return my-string))

     (status my-status)

     (category (:reference-return my-string))

     (message (:reference-return my-string)))

  …)

 

However for the access to the remaining arguments I’d need access to the stack-pointer to access and manually convert the arguments based on the message string, and I can’t find anything related to that in the documentation…

 

Has anyone done something like this?

 

Regs, Pierre.

 

--

Pierre R. Mai                                        <pmai@pmsf.de>

PMSF IT Consulting Pierre R. Mai                http://www.pmsf.de/

Blumenstr. 4                                          Goethestr. 32

85417 Marzling                                     87724 Ottobeuren

Tel. +49(0)8161/935 35 12                      +49(0)8332/936 69 13

Fax  +49(0)8161/935 35 08                      +49(0)8332/936 69 03

VAT ID / USt-ID Nr: DE 212838159                            Germany

 

Re: Defining callback functions with varargs

Unable to parse email body. Email id is 12375

Re: Defining callback functions with varargs

If you have access such that you can change the function signature, could you just pass a va_list instead and then pass that to vsprintf from within the Lisp code (I assume you are logging or similar, and "message" is the format)?

void myCallback(..., string msg, va_list args);

Now, for your foreign callable, args is just an integer/pointer you can pass to vsprintf() from within your lisp code.

Jeff M.
Pierre R. Mai
Monday, August 05, 2013 10:34 AM

Hi everyone,

 

currently I’m trying to define a callback function in Lispworks that accepts varargs (as that is the defined interface for the callback), i.e. the defined callback must match the following signature:

 

void myCallback(Component c, myString name, myStatus status, myString category,

 myString message, ...);

 

Defining a similar callback from Lisp for the non-variable arguments is simple, e.g.

 

(fli:define-foreign-callable ("myCallback" :result-type :void :calling-convention :cdecl)

    ((component component-ptr)

     (name (:reference-return my-string))

     (status my-status)

     (category (:reference-return my-string))

     (message (:reference-return my-string)))

  …)

 

However for the access to the remaining arguments I’d need access to the stack-pointer to access and manually convert the arguments based on the message string, and I can’t find anything related to that in the documentation…

 

Has anyone done something like this?

 

Regs, Pierre.

 

--

Pierre R. Mai                                        <pmai@pmsf.de>

PMSF IT Consulting Pierre R. Mai                http://www.pmsf.de/

Blumenstr. 4                                          Goethestr. 32

85417 Marzling                                     87724 Ottobeuren

Tel. +49(0)8161/935 35 12                      +49(0)8332/936 69 13

Fax  +49(0)8161/935 35 08                      +49(0)8332/936 69 03

VAT ID / USt-ID Nr: DE 212838159                            Germany

 

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