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

William Ott wottis at gmail.com
Thu Mar 19 08:19:14 PDT 2020


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20200319/0dd98518/attachment.htm>


More information about the Cuis-dev mailing list