Untitled

Published September 25, 2006
Advertisement
Ack, I know no one cares about my Pythong blabbery, but I've been spending a lot of time thinking about it (in one way or another). Anyway.

I've been working out how the shared data stuff is supposed to work. And I've got a prototype working, but it isn't pretty at all. And its only going to get worse from here; its hard as hell to make a nice user interface.

Anyway. For us to use our C structs in Pythong we have to prefix them with a bunch of Pythong data headers so Pythong knows how to eat it. This is easily wrappered -
template < class T >struct WRAPPER {	PyObject_HEAD	T data;};

Cool. So now we can just instantiate an instance of that template to create a wrappered version of the user's structs.

But then SHilbert came a long and was like "lol how do you handle live references?" and I was like "wtf.... OH DAMMIT".

Basically, if you declare yourself an instance of your user struct, say -

struct foo { ... };

void blah() {
foo myfoo;
call( "some_python_func", myfoo ); // takes a reference.
}

What happens is that struct foo has to get converted to struct WRAPPER. Which means a copy construction. Which means you're getting data passed by-value, not by-reference.

BUT WAIT!

What if, from Pythong -

myfoo = foo();
call( "some_c_func", myfoo );

The Pythong->C function handler will be called, and extract the struct foo from the struct WRAPPER* passed up from Pythong, then pass that (hopefully by refernce) to the expectant C-function. WHICH MEANS ITS BEING PASSED BY REFERENCE.

I'm not really sure what to do about this. I'm really really tempted to leave it like this, because, honestly, that's good enough for me. Wish I could do it by-ref both ways, but the limitations of C make it not so.

Opinions?
Previous Entry Untitled
Next Entry Untitled
0 likes 3 comments

Comments

Deyja
Quote:Anyway. For us to use our C structs in Pythong we have to prefix them with a bunch of Pythong data headers so Pythong knows how to eat it.


That's why I use AngelScript. I wouldn't touch python with a 10' stick.
September 26, 2006 04:45 AM
s_cloudx
Nice journal. Btw, I think you're RSS feed is broken. I can't subscribe to your journal. :(
September 26, 2006 09:46 PM
Mushu
whoa, it is. I'll have to put in a work request, thanks for bringing that to my attention!
September 26, 2006 10:22 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Untitled

5412 views

Untitled

1056 views

Untitled

1201 views

Untitled

1114 views

Untitled

1160 views

Untitled

1446 views

Untitled

1113 views

Untitled

1014 views

Untitled

1018 views

Untitled

1199 views
Advertisement