So, here the changes which should work (but i didn't tested).

And being on your place, i would get rid of
FMOD_SYSTEM class,
because you can just subclass  FmodSystem from NBExternalObject directly
(and use it in signatures)
and so it will be holding the handle, and naturally work as a
representation of external entity.
Also note that in this case
FmodSystem is alias to C  FMOD_SYSTEM*

so, for every function which expects FMOD_SYSTEM*, you should just use
FmodSystem,
and if it expects FMOD_SYSTEM**, you using FmodSystem*

basically, same as if you would have:

typedef FmodSystem FMOD_SYSTEM*;

in C.


On 22 November 2013 15:10, Igor Stasenko <siguc...@gmail.com> wrote:

>
>
>
> On 22 November 2013 05:09, Sean P. DeNigris <s...@clipperadams.com> wrote:
>
>> Igor Stasenko wrote
>> >> The better way is to subclass from NBExternalObject then
>> > which made exactly for such purposes, by holding an opaque handle to
>> > something (you don't care what is inside), and simplifies a lot of
>> things.
>>
>> I made "NBExternalObject subclass: #FMOD_SYSTEM".
>> I then tried to use it via:
>>         system := FMOD_SYSTEM new.
>>         err := self System_CreateNBExternalObject: system.
>> With callout:
>>         ^ self nbCall: #(FMOD_RESULT FMOD_System_Create(NBExternalObject
>> system)).
>>
>> For the argument type in the signature, for good measure I tried:
>> 1. NBExternalObject
>> 2. FMOD_SYSTEM
>> 3. NBExternalAddress
>> All three with zero, one, and two *'s after. The only one that didn't
>> report
>> some variety of "An instance of Xyz expected" was
>> "FMOD_System_Create(FMOD_SYSTEM system)" for which the library returns an
>> invalid argument error code.
>>
>> yet again, you miss the right solution: you must pass a pointer to where
> value will be stored
> (since function doing exactly that).
>
> so you should do it like:
> 1. "NBExternalObject subclass: #FMOD_SYSTEM".
>
> 2. method to call the function will look like following:
>   create: system
>     ^ self nbCall: #(FMOD_RESULT FMOD_System_Create(FMOD_SYSTEM * system)).
>
> 3. and call it like following:
>
>   system :=  FMOD_SYSTEM new.
>   self handleError: (self create: system) ifOk: [ ^ system ]
>
> 3a. optionally, you want want to initialize it just after you know that
> you obtained correct handle,
> to do that, you could do following:
>
> FMOD_SYSTEM class>>new
>   | system |
>   system :=  super new.
>   self handleError: (self create: system) ifOk: [ ^ self newWithHandle:
> system handle ]
>
> and newWithHandle: could look something like following:
>
> newWithHandle: aHandle
>
>  system := super basicNew.
>  system handle: aHandle.
>  ^ system initialize
>
> (because it is important to set the handle first, like that you can
> actually initialize something more
> by using it, which you logically do, just after creating a new handle.
> and note you must not call 'super initialize' then, because it will reset
> handle.)
> and i'm sure you can find more elegant solution :)
>
> btw if anyone wants to play with it:
>> 1.
>>     Gofer it
>>         smalltalkhubUser: 'SeanDeNigris' project: 'FMOD';
>>         package: 'FMOD';
>>         load.
>>
>> 2. Download the FMOD library for your platform:
>> - windows -
>>
>> http://www.fmod.org/download/fmodstudio/api/Win/fmodstudioapi10208win-installer.exe
>> - Mac -
>>
>> http://www.fmod.org/download/fmodstudio/api/Mac/fmodstudioapi10208mac-installer.dmg
>>
>> 3. Copy the library to "FileLocator imageDirectory / 'FMOD Programmers
>> API/api/lowlevel/lib/libfmod.dylib'"
>>
>> The working example is:
>> | sound |
>> sound := FmodSound fromFile: '/path/to/file.mp3' asFileReference.
>> [ sound play ] fork.
>>
>> The broken one described above is: "FMOD exampleNBExternalObject."
>>
>>
>>
>> -----
>> Cheers,
>> Sean
>> --
>> View this message in context:
>> http://forum.world.st/NativeBoost-Questions-while-wrapping-FMOD-tp4724116p4724192.html
>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>
>>
>
>
> --
> Best regards,
> Igor Stasenko.
>



-- 
Best regards,
Igor Stasenko.

Attachment: FmodSystem.st
Description: Binary data

Reply via email to