Hello,
NativeBoost doesn't allow me to pass a nil value instead of a String as a parameter for a 'const char*' function argument. When I use nil I get a failure with lastError=1 Is this by design? If so, is there an alternative? Jan.
|
On 24 August 2012 17:00, Jan van de Sandt <[hidden email]> wrote:
> Hello, > > NativeBoost doesn't allow me to pass a nil value instead of a String as a > parameter for a 'const char*' function argument. When I use nil I get a > failure with lastError=1 > > Is this by design? If so, is there an alternative? > yess.. by default if you use in signature a 'String' as argument type then the FFI routine will only accept an instances of variable-byte objects (which a ByteStrings are). But there is an option #optStringOrNull which will also allows passing a nil object as argument (which will be converted to NULL pointer value) so, in your binding you must specify this option: mymethod: string <...> ^ self nbCall: #( void whatever(String string)) options: #( optStringOrNull ) so, for passing null , you can simply pass a nil as argument: self mymethod: nil. > Jan. -- Best regards, Igor Stasenko. |
Igor
we should collect all the emails of Jan and turn them into a section in the FFI chapter. Stef On Aug 24, 2012, at 5:36 PM, Igor Stasenko wrote: > On 24 August 2012 17:00, Jan van de Sandt <[hidden email]> wrote: >> Hello, >> >> NativeBoost doesn't allow me to pass a nil value instead of a String as a >> parameter for a 'const char*' function argument. When I use nil I get a >> failure with lastError=1 >> >> Is this by design? If so, is there an alternative? >> > yess.. > > by default if you use in signature a 'String' as argument type > then the FFI routine will only accept an instances of variable-byte > objects (which a ByteStrings are). > But there is an option #optStringOrNull > which will also allows passing a nil object as argument (which will be > converted to NULL pointer value) > > so, in your binding you must specify this option: > > mymethod: string > <...> > ^ self nbCall: #( void whatever(String string)) options: #( optStringOrNull ) > > so, for passing null , you can simply pass a nil as argument: > > self mymethod: nil. > >> Jan. > > > > -- > Best regards, > Igor Stasenko. > |
On 24 August 2012 17:46, Stéphane Ducasse <[hidden email]> wrote:
> Igor > > we should collect all the emails of Jan and turn them into a section in the FFI chapter. > sure. meanwhile i will write a section about strings and structures on NB-Help. > Stef > > On Aug 24, 2012, at 5:36 PM, Igor Stasenko wrote: > >> On 24 August 2012 17:00, Jan van de Sandt <[hidden email]> wrote: >>> Hello, >>> >>> NativeBoost doesn't allow me to pass a nil value instead of a String as a >>> parameter for a 'const char*' function argument. When I use nil I get a >>> failure with lastError=1 >>> >>> Is this by design? If so, is there an alternative? >>> >> yess.. >> >> by default if you use in signature a 'String' as argument type >> then the FFI routine will only accept an instances of variable-byte >> objects (which a ByteStrings are). >> But there is an option #optStringOrNull >> which will also allows passing a nil object as argument (which will be >> converted to NULL pointer value) >> >> so, in your binding you must specify this option: >> >> mymethod: string >> <...> >> ^ self nbCall: #( void whatever(String string)) options: #( optStringOrNull ) >> >> so, for passing null , you can simply pass a nil as argument: >> >> self mymethod: nil. >> >>> Jan. >> >> >> >> -- >> Best regards, >> Igor Stasenko. >> > > -- Best regards, Igor Stasenko. |
On Aug 24, 2012, at 5:49 PM, Igor Stasenko wrote: > On 24 August 2012 17:46, Stéphane Ducasse <[hidden email]> wrote: >> Igor >> >> we should collect all the emails of Jan and turn them into a section in the FFI chapter. >> > sure. > meanwhile i will write a section about strings and structures on NB-Help. excellent idea. This evening I will read it if I do not fall asleep before since I should read mariano's paper ;D Stef > >> Stef >> >> On Aug 24, 2012, at 5:36 PM, Igor Stasenko wrote: >> >>> On 24 August 2012 17:00, Jan van de Sandt <[hidden email]> wrote: >>>> Hello, >>>> >>>> NativeBoost doesn't allow me to pass a nil value instead of a String as a >>>> parameter for a 'const char*' function argument. When I use nil I get a >>>> failure with lastError=1 >>>> >>>> Is this by design? If so, is there an alternative? >>>> >>> yess.. >>> >>> by default if you use in signature a 'String' as argument type >>> then the FFI routine will only accept an instances of variable-byte >>> objects (which a ByteStrings are). >>> But there is an option #optStringOrNull >>> which will also allows passing a nil object as argument (which will be >>> converted to NULL pointer value) >>> >>> so, in your binding you must specify this option: >>> >>> mymethod: string >>> <...> >>> ^ self nbCall: #( void whatever(String string)) options: #( optStringOrNull ) >>> >>> so, for passing null , you can simply pass a nil as argument: >>> >>> self mymethod: nil. >>> >>>> Jan. >>> >>> >>> >>> -- >>> Best regards, >>> Igor Stasenko. >>> >> >> > > > > -- > Best regards, > Igor Stasenko. > |
Free forum by Nabble | Edit this page |