Re: wrapping C code - my exercise in incompetence.

new topic     » goto parent     » topic index » view thread      » older message » newer message
ssallen said...

My new issue is how to deal with this:

ASSIMP_API C_STRUCT aiLogStream aiGetPredefinedLogStream( 
        C_ENUM aiDefaultLogStream pStreams, 
        const char* file); 

That function appears to return an actual structure and not a pointer to one. How do I deal with that? Do I have to duplicate the structure in memory by allocating and peeking/poking?

It's passing the structure by value instead of by reference, which is another big no-no in many books. Unfortunately, Euphoria is completely incapable of dealing with this correctly. I have dealt with this first-hand, see: define_c_func/proc and 64-bit return types.

I had to resort to writing a "shim" library (dll/so) in C to push the structure from the stack (pass-by-value) to the heap (pass-by-reference, a.k.a. pointers) and back again. I'm afraid you may have to do the same. I'd be glad to help, if you need. You may also be able to use Assembly code to do this, but I've had no such luck. I'm still quite rusty when it comes to Assembly.

ssallen said...

and then, of course, the aiLogStreamCallback:

typedef void (*aiLogStreamCallback)(const char* /* message */, char* /* user */);   

That is not a real function. It is a typedef, which defines how your function should look when passing its reference to other functions. You just need to setup a call_back() and pass that value to whatever function(s) call for it.

public function aiLogStreamCallback( atom pMessage /* char* */, atom pUser /* char* */ ) 
     
    sequence message = peek_string( pMessage ) 
    sequence user = peek_string( pUser ) 
 
    -- do what you need here 
 
    return 0 
end function 
constant alLogStreamCallback_cb = call_back( routine_id("aiLogStreamCallback") ) 

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu