On 31 August 2012 16:16, Guy Hylton <[email protected]> wrote:
>
>
> On Fri, Aug 31, 2012 at 2:17 PM, Igor Stasenko <[email protected]> wrote:
>>
>> On 31 August 2012 15:03, Guy Hylton <[email protected]> wrote:
>> > I am looking for some NativeBoost advice on the best way of using a
>> > structure with an containing a char array like the following:
>> >
>> > int level
>> > int number
>> > char[256] msgText
>> > ulong elapsedTime
>> >
>> > Currently I am using an NBExternalAddress returned by
>> > NativeBoost>>allocate:
>> > because the external library holds onto the address and using byteAt: to
>> > see
>> > what is going on in the structure while I get used to the external
>> > library
>> > API.
>> >
>> > I can think of a couple of options, create my own NBExternalType
>> > subclass
>> > which I can use in an NBExternalStructure or subclass
>> > NBExternalAddress/Object with methods to extract the appropriate data,
>> > or
>> > have I missed the simple solution?
>> >
>>
>> well, there's no array-types support..
>> so, what you can do is to place dummy fields instead of array.. i.e.
>>
>> int level
>>  int number
>>  char msgText1
>>  char msgText2
>>  ...
>>  char msgText256
>>
>>  ulong elapsedTime
>>
>> which should do the trick.
>>
>> (of course, not necessary to use chars, you can use ints, so it will
>> be only 64 dummies instead of 256 ;)
>>
>> And of course a better way of doing that is to create a special
>> NBExternalType subclass , lets say NBExternalTypeArray
>> which takes a basic type and number of elements.
>> And it should answer correct #instanceSize and other related things,
>> as well as implement methods for pushing/storing and reading the
>> values of such type.
>
>
> A subclass of NBExternalType looked like the better option when looking
> through the existing classes for a solution but I wasn't sure that I was
> ready to start writing assembler.
>

You can always try and see what you get. Assembler is pretty dumb thing.
Each instruction doing something , so if you put them in right order,
there's little space for faults.
Unlike from C, where you can put things in right order (making compiler happy),
but leave a bugs which can sit there undiscovered for years :)

> I already feel like one of the Sorcerers Apprentices just using NativeBoost
> to interface to an external library, let alone adding some assembler
> incantations to my own spells :-).
>
Hehe.. Well, you cannot avoid some sorcery when using FFI.

>>
>> I will work on adding that in closest days.
>
>
> That would be great!  In the meantime I will have a go at writing my own
> NBExternalType subclass to handle the specific situation I have come across;
> NBExternalString>>coerceReturnValue: looks like a good place to start.  Even
> if I don't get very far it will hopefully help me understand your solution.
>

Also look for NBExternalStructureType, like #pushAsValue: .

>>
>> It is not too hard to implement ;)
>
>
> No, not for a first class wizard :-)
>
sure, i don't expect that you will be able to start hacking assembler
from beginning,
but as soon as you get some basics, you can do the same or even better :)

-- 
Best regards,
Igor Stasenko.

Reply via email to