Lisp HUG Maillist Archive

Getting the FLI to convert between types

If I have the following foreign function:

(define-foreign-function (test "test")
    ((x :float))
  :result-type :void)

And I call it with an integer value:

(test 1)

This produces an error that '1' is not of type ':float'. I was
wondering if there was something I could do to avoid this, or force
Lisp to convert it before passing it onto the foreign function?

Jeff M.

-- 
http://www.retrobyte.org
mailto:massung@gmail.com


Re: Getting the FLI to convert between types

On Wed, 1 Dec 2004 00:55:42 -0600, Jeff Massung <massung@gmail.com> wrote:

> If I have the following foreign function:
>
> (define-foreign-function (test "test")
>     ((x :float))
>   :result-type :void)
>
> And I call it with an integer value:
>
> (test 1)
>
> This produces an error that '1' is not of type ':float'. I was
> wondering if there was something I could do to avoid this, or force
> Lisp to convert it before passing it onto the foreign function?

Why don't you simply do something like

(define-foreign-function (%test "test")
    ((x :float))
  :result-type :void)

(defun test (x)
  (%test (float x)))

Cheers,
Edi.


Re: Getting the FLI to convert between types

> Why don't you simply do something like
> 
> (define-foreign-function (%test "test")
>     ((x :float))
>   :result-type :void)

Normally, I would, but this is for OpenGL bindings, and there are
quite a few functions there that take floating point values. It would
be nice to get around this with something simple. Thanks for the
suggestion, though ;)

Jeff M.


Re: Getting the FLI to convert between types

Jeff Massung <massung@gmail.com> writes:

>> Why don't you simply do something like
>> 
>> (define-foreign-function (%test "test")
>>     ((x :float))
>>   :result-type :void)
>
> Normally, I would, but this is for OpenGL bindings, and there are
> quite a few functions there that take floating point values. It would
> be nice to get around this with something simple. Thanks for the
> suggestion, though ;)
How about writing a Makro around it?

Regards
Friedrich


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