chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] ffi howto


From: Richard
Subject: Re: [Chicken-users] ffi howto
Date: Fri, 21 Nov 2014 18:38:50 +0000

Hello again,

I forgot something,
as uv-idle-start takes a pointer as its second argument the function
must be called with like so:
(uv-idle-start idler-ref (location wait_for_a_while))

cheers,
Richard

Richard writes:

> Hello Omar,
>
> The problem with your code is that wait-for-a-while must be declared as
> an external function; like so:
>
> (define-external
>   (wait_for_a_while ((c-pointer uv-idle-t) handle))
>   void
>   (let lp ((counter 0))
>     (if (>= counter 10000000)
>       (uv-idle-stop handle)
>       (lp (+ counter 1)))))
>
> note that the name of the function must be a valid C function name, so
> it cannot be dash-seperated. Also looking at the libub documentation,
> the callback did not have a status argument.
>
> An external function that is going to call such a callback function must
> be declared using 'foreign-safe-lambda' instead of
> 'foreign-lambda'. Thus uv-run must be declared as such:
>
> (define uv-run
>   (foreign-safe-lambda int "uv_run" (c-pointer uv-loop-t) int))
>
> Hope this helps and good luck,
> Richard
>
>
> address@hidden writes:
>
>> Hello,
>>
>> I need some help getting started with ffi. 
>>
>> I am attempting to bind libuv to scheme code.
>>
>> My chicken scheme code at http://pastebin.com/bwja0yet fails with the
>> following error.
>>
>> The following code fails with the following:
>>
>> Error: bad argument count - received 152135942 but expected 2: 0
>>
>>      Call history:
>>
>>      uv.scm:33: uv-default-loop        
>>      uv.scm:33: uv-idle-init   
>>      uv.scm:34: uv-idle-start          
>>      uv.scm:36: uv-default-loop        
>>      uv.scm:36: uv-run               <--
>>
>>
>> I am attempting to port the following C code.
>>
>> http://pastebin.com/63gP8HFT
>>
>> - Omar
>>
>> _______________________________________________
>> Chicken-users mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/chicken-users

-- 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]