[Cuis-dev] [FFI] Passing struct by value not working

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Thu Mar 19 14:44:25 PDT 2020


Hello,
Please indicate platform, os, FFI and VM version.

Le jeu. 19 mars 2020 à 16:19, William Ott via Cuis-dev <
cuis-dev at lists.cuis.st> a écrit :

> Hello everyone,
>
> I'm trying to write a FFI wrapper for the game dev library raylib [1]. But
> I encountered an issue when passing custom ExternalStructures to some
> library functions.
>
> For example I created the following struct:
>
> !classDefinition: #RaylibVector2 category: #'Game-Raylib'!
> ExternalStructure subclass: #RaylibVector2
>   instanceVariableNames: ''
>   classVariableNames: ''
>   poolDictionaries: ''
>   category: 'Game-Raylib'!
> !classDefinition: 'RaylibVector2 class' category: #'Game-Raylib'!
> RaylibVector2 class
>   instanceVariableNames: ''!
>
> !RaylibVector2 class methodsFor: 'compiling' stamp: 'smotti 3/19/2020
> 22:51:40'!
> fields
>   "self defineFields"
>   ^ #( (x 'float') (y 'float') )! !
>
> And here the FFI method:
>
> !Raylib class methodsFor: 'as yet unclassified' stamp: 'smotti 3/19/2020
> 22:52:44'!
> apiDrawCircleVatPosition: center radius: radius color: color
>
> <apicall: void 'DrawCircleV' (RaylibVector2 float RaylibColor) module:
> 'libraylib'>
> ^ self externalCallFailed ! !
>
> What i expect is that this will draw a circle into a window with the
> center being at the coordinates defined by RaylibVector2.
>
> It works for RaylibColor, which is another struct with ulong values to
> define an RGB color with and alpha value. The RaylibVector2 works also when
> returned from a function for example in the case of GetMousePosition. Also
> drawing works in general by using DrawCircle or DrawRectangle.
>
> I checked the FFI-Test package for examples also read through the
> documentation and classes of the other FFI classes. And also tried
> different approaches but it just doesn't work.
> So I have no clue why it doesn't work in this case (and in others, i.e.
> when passing a RaylibRectangle).
>
> You can find a package with the classes and examples at [2].
>
> Thank you very much for your help in advance.
>
> Kind regards,
> smotti
>
> [1] https://www.raylib.com/index.html
> [2] https://pastebin.com/4LSs6SNX
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20200319/e959c9f2/attachment.htm>


More information about the Cuis-dev mailing list