Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411615 Posts in 69390 Topics- by 58447 Members - Latest Member: sinsofsven

May 10, 2024, 06:11:29 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Boost::Python
Pages: [1]
Print
Author Topic: Boost::Python  (Read 1326 times)
Garthy
Level 9
****


Quack, verily


View Profile WWW
« on: December 07, 2009, 04:10:25 PM »

I was wondering if anyone has had a look at Boost::Python in the context of embedding a scripting language into a C/C++ game. In this context, what did you think of it?

I know that Python is a quality and mature scripting language (not my favourite, but it doesn't have to be), so that bit isn't a problem. I'm a bit underwhelmed by the poor Boost::Python documentation though- it looks like it might be a good reference, but it's pretty awful for a new user. I'm trying to figure out if it's going to be worth the trouble.

Has anyone undertaken this particular journey before? Was it worth it? What were your experiences, both good and bad?

I should point out that I'm probably not going to be digging into this seriously for a while- I'm just exploring at the moment to find out what other people think of it, so I have an idea if it is likely that I'll be successful if I try to use it.
Logged
Ben Kuhn
Level 0
***


View Profile
« Reply #1 on: December 07, 2009, 04:43:07 PM »

I didn't have many problems with the docs, though I didn't dig very deeply.

I did, however, find it to be rather clunky compared to, say, SWIG (which serves nearly the same purpose, and with which I have more experience). I think that B:: P handles Boost:: shared_ptr better than SWIG, but otherwise they're pretty even functionality-wise. And B:: P requires far more typing, and the templates take forever to compile. I also find SWIG to be cleaner since it doesn't rely on confusing template black magic. On the other hand, SWIG is an additional step in your toolchain that might not be worth it.

So I can't contrast them technically very well, but I can give you the general impression that I got, which is that you should look at SWIG as a possibility if B:: P isn't doing it for you. Hope that helps.
Logged
Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #2 on: December 07, 2009, 06:48:22 PM »

I didn't have many problems with the docs, though I didn't dig very deeply.

I did, however, find it to be rather clunky compared to, say, SWIG (which serves nearly the same purpose, and with which I have more experience). I think that B:: P handles Boost:: shared_ptr better than SWIG, but otherwise they're pretty even functionality-wise. And B:: P requires far more typing, and the templates take forever to compile. I also find SWIG to be cleaner since it doesn't rely on confusing template black magic. On the other hand, SWIG is an additional step in your toolchain that might not be worth it.

So I can't contrast them technically very well, but I can give you the general impression that I got, which is that you should look at SWIG as a possibility if B:: P isn't doing it for you. Hope that helps.

Yes, it has, thankyou. Smiley

Interesting. I do use shared_ptr rather extensively already, but I *also* use SWIG a little bit- mostly to export some segments of code that can be run in Ruby scripts- ie. extending rather than embedding. What I'd like to do is the other way around though- embedding a script into my code, rather than setting code up to be called from a script.

Basically if I can do a call from A (C/C++) to B (eg. Python) back to a different function in A (C/C++) that I pushed into the scripting environment somehow, then it's doing what I'm after. Anyway, is this the kind of thing that you worked with? A quick skim of the swig docs seems to give the typical "extending" examples, but skimps on the "embedding". I find that enormously frustrating, and it's why I have to ask rather than just being able to look up the docs for a solution.
Logged
Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #3 on: December 07, 2009, 07:01:01 PM »

Ah:

http://wiki.python.org/moin/boost.python/EmbeddingPython

"Boost.Python does not provide all the constructs necessary for embedding Python in a C++ application"

"Note:  Because there is very little documentation on a lot of this, I am not entirely sure that the methods I am describing are the best to accomplish the task. If there is a better way, please write it up here."

Bugger. Another incomplete solution.
Logged
Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #4 on: December 07, 2009, 07:56:21 PM »

Okay, I'm asking a more general question on scripting languages here instead:

http://forums.tigsource.com/index.php?topic=9707.0
Logged
Ben Kuhn
Level 0
***


View Profile
« Reply #5 on: December 08, 2009, 01:21:09 PM »

You can embed Python from SWIG. Each cool_program.c file that SWIG produces will have a function called something like 'void init_cool_program()'. In your main function, just call
Code:
Py_Initialize();
init_cool_program();
Tada! embedded Python + SWIG.

I believe there's a similar method for Boost:: Python - that particular discouraging line is actually there because Python provides the rest of the facilities itself.
Logged
Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #6 on: December 08, 2009, 02:31:03 PM »

Thanks for that.

I'm not entirely sure how that example is going to map back to the problem I am trying to solve- this might be because my SWIG knowledge is still very basic. Also, I'm pretty sure that doesn't touch the A->B->A scenario I described. The general question in the link above (and below) provides a better explanation of what I'm after. I don't suppose you've personally done embedding (not extending) of this nature- either just simple Python invocations from C/C++, or ideally the A->B->A style described above or in the link here:

http://forums.tigsource.com/index.php?topic=9707.0

?
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic