FFI signatures

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

FFI signatures

Annick
What signature should I use for a callback ?
‘ulong’ does not seem to work

Annick
Reply | Threaded
Open this post in threaded view
|

Re: FFI signatures

EstebanLM
it doesn’t really matters.
what you need to be sure for alien is that you have an “evaluator” for that callback.

for example, the

exampleCqsort

uses this callback:

int (*)(const void *, const void *)

so, in “Callback” instance side, you can find this definition:

voidstarvoidstarRetint: callbackContext sp: spAlien
        <signature: 'int (*)(const void *, const void *)' abi: 'IA32'>
        ^callbackContext wordResult:
                (block
                        value: (Alien forPointer: (spAlien unsignedLongAt: 1))
                        value: (Alien forPointer: (spAlien unsignedLongAt: 5)))

So, you need to add a method extension, something like:

ulongulongRetulong: callbackContext sp: spAlien
        <signature: ‘ulong (*)(ulong, ulong)' abi: 'IA32'>
        ^callbackContext wordResult:
                (block
                        value: (spAlien unsignedLongAt: 1)
                        value: (spAlien unsignedLongAt: 5))

then you can declare your callback something like:

        cb := Callback
                signature: 'ulong (*)(ulong, ulong)'
                block: [ :arg1 :arg2 | ... ].

that has to work :)

yes, is pretty complicated, and yes, you need to do a method for each kind of different signature you want to use.
but well, is the way it works now :)

Esteban


On 09 Sep 2014, at 12:00, Annick Fron <[hidden email]> wrote:

> What signature should I use for a callback ?
> ‘ulong’ does not seem to work
>
> Annick


Reply | Threaded
Open this post in threaded view
|

Re: FFI signatures

Annick
If I have
ulong ulong long long ulong
should I look in
unsignedLongAt:
1
5
9
13
17
(with an increment of 4)
??

Le 9 sept. 2014 à 15:43, Esteban Lorenzano <[hidden email]> a écrit :

> it doesn’t really matters.
> what you need to be sure for alien is that you have an “evaluator” for that callback.
>
> for example, the
>
> exampleCqsort
>
> uses this callback:
>
> int (*)(const void *, const void *)
>
> so, in “Callback” instance side, you can find this definition:
>
> voidstarvoidstarRetint: callbackContext sp: spAlien
> <signature: 'int (*)(const void *, const void *)' abi: 'IA32'>
> ^callbackContext wordResult:
> (block
> value: (Alien forPointer: (spAlien unsignedLongAt: 1))
> value: (Alien forPointer: (spAlien unsignedLongAt: 5)))
>
> So, you need to add a method extension, something like:
>
> ulongulongRetulong: callbackContext sp: spAlien
> <signature: ‘ulong (*)(ulong, ulong)' abi: 'IA32'>
> ^callbackContext wordResult:
> (block
> value: (spAlien unsignedLongAt: 1)
> value: (spAlien unsignedLongAt: 5))
>
> then you can declare your callback something like:
>
> cb := Callback
> signature: 'ulong (*)(ulong, ulong)'
> block: [ :arg1 :arg2 | ... ].
>
> that has to work :)
>
> yes, is pretty complicated, and yes, you need to do a method for each kind of different signature you want to use.
> but well, is the way it works now :)
>
> Esteban
>
>
> On 09 Sep 2014, at 12:00, Annick Fron <[hidden email]> wrote:
>
>> What signature should I use for a callback ?
>> ‘ulong’ does not seem to work
>>
>> Annick
>