Hello,
I was running through the docs and doing some experiments but couldn't find a way to convert an Array of Strings to char**. Somewhere I read that was possible to return an int** using "#(#ptr #{CInt})". I tried to pass #( 1 2 3) as parameter using this scheme but got "Attempt to pass an instance of Array as a void *". Any ideas? Thanks Thiago _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
On Sun, Jan 9, 2011 at 15:57, Thiago Silva <[hidden email]> wrote:
> Hello, > > I was running through the docs and doing some experiments but couldn't > find a way to convert an Array of Strings to char**. A "CString new: 5" is an array of 5 strings (a pointer to 5 char*). Something like cstring at: 3 put: 'abc' would fill the fourth pointer and automatically allocate memory for the 'abc' string. Note that CStrings can be a good source of memory leaks since you have to free the elements as well. > Somewhere I read > that was possible to return an int** using "#(#ptr #{CInt})". I tried > to pass #( 1 2 3) as parameter using this scheme but got "Attempt to > pass an instance of Array as a void *". No, Smaltalk objects are not automatically converted to instances from the CObject hierarchy. Paolo _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
On Jan 9, 2011, at 6:14 PM, Paolo Bonzini wrote:
> No, Smaltalk objects are not automatically converted to instances from > the CObject hierarchy. Could it be interesting to have message like asCUChar, asCInt...? This could avoid writing too mush parenthesis for example: aCObject at: 1 put: 230 asCUChar. > > Paolo Mathieu __________________________________________________ Do You Yahoo!? En finir avec le spam? Yahoo! Mail vous offre la meilleure protection possible contre les messages non sollicités http://mail.yahoo.fr Yahoo! Mail _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
On Sun, Jan 9, 2011 at 19:50, Mathieu Suen <[hidden email]> wrote:
> On Jan 9, 2011, at 6:14 PM, Paolo Bonzini wrote: > >> No, Smaltalk objects are not automatically converted to instances from >> the CObject hierarchy. > > Could it be interesting to have message like asCUChar, asCInt...? > This could avoid writing too mush parenthesis for example: > aCObject at: 1 put: 230 asCUChar. I don't think this would be used very often. Your example would not be equivalent to aCObject[1] = 230; but rather char *p = malloc (1); *p = 230; aCObject[1] = p; Paolo _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
On Jan 9, 2011, at 10:43 PM, Paolo Bonzini wrote:
> On Sun, Jan 9, 2011 at 19:50, Mathieu Suen <[hidden email]> wrote: >> On Jan 9, 2011, at 6:14 PM, Paolo Bonzini wrote: >> >>> No, Smaltalk objects are not automatically converted to instances from >>> the CObject hierarchy. >> >> Could it be interesting to have message like asCUChar, asCInt...? >> This could avoid writing too mush parenthesis for example: >> aCObject at: 1 put: 230 asCUChar. > > I don't think this would be used very often. Your example would not > be equivalent to > > aCObject[1] = 230; > > but rather > > char *p = malloc (1); > *p = 230; > aCObject[1] = p; I see yes. So I have a question. When I was playing with cairo I thought there was no other way than this to write on a surface: cpngSurface := Cairo.CairoPngSurface on: 'test.png' extent: width@height. data := Cairo.Cairo imageSurfaceGetData: cpngSurface cairoSurface. .. data at: (i*4) + (j*stride) + 3 put: (CChar value: 255) type: CChar. #imageSurfaceGetData: returns an instance of CObject. How to make #imageSurfaceGetData: returns a CCharArray to do something like: data at: (i*4) + (j*stride) + 3 put: 255 ? Thanks > > Paolo Mth __________________________________________________ Do You Yahoo!? En finir avec le spam? Yahoo! Mail vous offre la meilleure protection possible contre les messages non sollicités http://mail.yahoo.fr Yahoo! Mail _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
On 01/09/2011 11:31 PM, Mathieu Suen wrote:
> When I was playing with cairo I thought there was no other way than this to write > on a surface: > cpngSurface := Cairo.CairoPngSurface on: 'test.png' extent: width@height. > data := Cairo.Cairo imageSurfaceGetData: cpngSurface cairoSurface. > .. > data at: (i*4) + (j*stride) + 3 put: (CChar value: 255) type: CChar. > > #imageSurfaceGetData: returns an instance of CObject. > How to make #imageSurfaceGetData: returns a CCharArray to do something like: > data at: (i*4) + (j*stride) + 3 put: 255 ? Something like this? diff --git a/packages/cairo/CairoFuncs.st b/packages/cairo/CairoFuncs.st index e3af859..e0316c0 100644 --- a/packages/cairo/CairoFuncs.st +++ b/packages/cairo/CairoFuncs.st @@ -96,7 +96,7 @@ CairoContext.'> ] Cairo class >> imageSurfaceGetData: surface [ - <cCall: 'cairo_image_surface_get_data' returning: #cObject args: #(#cObject)> + <cCall: 'cairo_image_surface_get_data' returning: #{CByte} args: #(#cObject)> ] Cairo class >> imageSurfaceGetHeight: filename [ diff --git a/packages/cairo/CairoSurface.st b/packages/cairo/CairoSurface.st index ba82e5e..097dcfd 100644 --- a/packages/cairo/CairoSurface.st +++ b/packages/cairo/CairoSurface.st @@ -296,6 +296,11 @@ CairoLoadableFileSurface subclass: CairoPngSurface [ ^Cairo imageSurfaceCreateFromPng: filename ] + data [ + <category: 'C interface'> + ^Cairo imageSurfaceGetData: self cairoSurface + ] + save [ "Save the contents of the surface to the PNG file specified by #filename." Paolo _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
----- Message d'origine ----
> De : Paolo Bonzini <[hidden email]> > > On 01/09/2011 11:31 PM, Mathieu Suen wrote: > > When I was playing with cairo I thought there was no other way than this to >write > > on a surface: > > cpngSurface := Cairo.CairoPngSurface on: 'test.png' extent: width@height. > > data := Cairo.Cairo imageSurfaceGetData: cpngSurface cairoSurface. > > .. > > data at: (i*4) + (j*stride) + 3 put: (CChar value: 255) type: CChar. > > > > #imageSurfaceGetData: returns an instance of CObject. > > How to make #imageSurfaceGetData: returns a CCharArray to do something > > data at: (i*4) + (j*stride) + 3 put: 255 ? > > Something like this? > > diff --git a/packages/cairo/CairoFuncs.st b/packages/cairo/CairoFuncs.st > index e3af859..e0316c0 100644 > --- a/packages/cairo/CairoFuncs.st > +++ b/packages/cairo/CairoFuncs.st > @@ -96,7 +96,7 @@ CairoContext.'> > ] > > Cairo class >> imageSurfaceGetData: surface [ > - <cCall: 'cairo_image_surface_get_data' returning: #cObject args: >#(#cObject)> > + <cCall: 'cairo_image_surface_get_data' returning: #{CByte} args: >#(#cObject)> > ] > > Cairo class >> imageSurfaceGetHeight: filename [ > diff --git a/packages/cairo/CairoSurface.st b/packages/cairo/CairoSurface.st > index ba82e5e..097dcfd 100644 > --- a/packages/cairo/CairoSurface.st > +++ b/packages/cairo/CairoSurface.st > @@ -296,6 +296,11 @@ CairoLoadableFileSurface subclass: CairoPngSurface [ > ^Cairo imageSurfaceCreateFromPng: filename > ] > > + data [ > + <category: 'C interface'> > + ^Cairo imageSurfaceGetData: self cairoSurface > + ] > + > save [ > "Save the contents of the surface to the PNG file specified by > #filename." > > Yeap :) Thanks > Paolo > _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
Free forum by Nabble | Edit this page |