[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] pass by value and callbacks
From: |
r |
Subject: |
Re: [Chicken-users] pass by value and callbacks |
Date: |
Wed, 12 Mar 2014 13:43:40 +0400 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
Hello pluijzer
As i know chicken didnt have pass-by-value FFI type.
This is little bit verbose workaround. Note that you should use
foreign-safe-lambda for callbacks from C.
(import scheme chicken foreign)
#>
typedef struct { int x, y; } Point;
typedef void (*SomeCallbackFuncType)(Point point);
void someFunc(SomeCallbackFuncType callback)
{
Point p = {1, 1};
callback(p);
}
static void callbackFunctionJumper(Point point)
{
callbackFunction(&point);
}
<#
(define-external (callbackFunction (c-pointer point))
void
(print "Hello from callback!"))
((foreign-safe-lambda* void () "someFunc(callbackFunctionJumper);"))
Hello chickeners,
I am trying to wrap a function that accepts a function pointer with an
argument to a struct passed by value.
I don't know how to do this (and fear it is not possible) but maybe
somebody else has a solution.
A little example of what I mean:
----
#>
typedef struct { int x, y; } Point;
typedef void (*SomeCallbackFuncType)(Point point);
void someFunc(SomeCallbackFuncType callback)
{
Point p = {1, 1};
callback(p);
}
<#
(define-external (callbackFunction (??? point))
void
(print "Hello from callback!"))
((foreign-lambda void "someFunc" c-pointer) #$callbackFunction)
----
I don't actually need the the value of the object in my callback.
Maybe that helps.
Thank you in advance,
Pluijzer
_______________________________________________
Chicken-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/chicken-users