Re: [Pharo-users] Can't able to understand the code
actually i am just exploring UFFI from the pdf "Calling Foreign Functions with Pharo" there one section is for external objects so i cant understand that code what i attach as screenshot above. can u able to explain what actually happen here ?? -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Hi Shawon, where did you get the docs? Have you tried the latest version (january/february this year) http://books.pharo.org/booklet-uffi/ <http://books.pharo.org/booklet-uffi/> ?
El 8 abr 2020, a las 4:44, shawon58 <shawonhoque58@gmail.com> escribió:
actually i am just exploring UFFI from the pdf "Calling Foreign Functions with Pharo" there one section is for external objects so i cant understand that code what i attach as screenshot above. can u able to explain what actually happen here ??
-- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Hi I'm not a FFI expert, and you code may not be the latest FFI version. However, If I look at it from Pharo side: When you want to use Athens with Cairo backend, you have to initialize its surface using a call like: surface := AthensCairoSurface extent: self extent Note that I'm calling a class method of AthensCairoSurface. In this example, 'self extent' will give you the size of the rectangle used by Morph for its bounds size. This, in turn, will call AthensCairoSurface class >> extent: anExtent  ^self extent: anExtent format: CAIRO_FORMAT_ARGB32 and you reach: AthensCairoSurface class >> extent: anExtent format: aFormat^ ( self primImage: aFormat width: anExtent x height: anExtent y + 1) initialize Which lead you to: primImage: aFormat width: aWidth height: aHeight ^ self ffiCall: #(AthensCairoSurface cairo_image_surface_create (int aFormat,                                                         int aWidth,                                                         int aHeight) )
From there, you have linked your pharo code done to initialize a Cairo surface. This will do a C call like:
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, aWidth, aHeight) This C call is documented here: https://www.cairographics.org/manual/cairo-Image-Surfaces.html, <https://www.cairographics.org/manual/cairo-Image-Surfaces.html> with surface enum here: https://www.cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-... Through the magic of FFI, It'll return an instance of AthensCairoSurface you''ll be able to use directly in your Pharo code. You can have a look to AthensFlakeDemo in Athens-Demo for a full working example. Renaud Apr. 7, 2020, 22:44 by shawonhoque58@gmail.com:
actually i am just exploring UFFI from the pdf "Calling Foreign Functions with Pharo" there one section is for external objects so i cant understand that code what i attach as screenshot above. can u able to explain what actually happen here ??
-- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
participants (3)
-
Guillermo Polito -
Renaud de Villemeur -
shawon58