Archived

This topic is now archived and is closed to further replies.

Horn

Python scripting

Recommended Posts

Before you groan saying ''here is another fool wondering if python is good for games'' read on a bit please. I am trying to embed python in my game but I''m not having much luck. I''ve read the samples in the python source and the docs but they''re not much use. I''ve searched the forums and google but I haven''t been able to find any tutorials on the subject. Could I find someone willing to ''tutor'' me (basically I ask stupid questions till I get the hang of it) or does anyone have any resources they could share with me?

Share this post


Link to post
Share on other sites

Sorry, don''t know much about Python, don''t know much about SWIG, but it looks like a handy tool for automating all the chicken-waving stuff when you''re embedding scripting languages.

http://www.swig.org/

Share this post


Link to post
Share on other sites
SWIG is an excellent tool for creating wrappers for Python. I have had some trouble when using some advanced features in C++ - for example I had to write my own python code to allow me to call a python function as if it were an overridden C++ virtual function instead of using the generated code.

For the vast majority of things it''ll handle them easily. You could try Boost:ython if swig is not what you''re looking for, I''ve never used it though so I can''t say what it''s like.

HTH
Andrew

Share this post


Link to post
Share on other sites
boost:ython is a nice library, and one with less caveats than most binding generators. The new version of it (which I think is still in beta) is much better, tho; I''m not sure if it''s publicly available yet, but if not, you could probably get a copy from the maintainer.

Have you considered other scripting languages, such as Lua or Ruby? I haven''t used Ruby much, but many people swear by its OO capabilities. As for Lua, many people prefer its simplicity and ease of integration over those of Python. And SWIG will work with it, too.



Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
on the off chance you don''t know,

1) SWIG is also a useful wrapper for Perl.
2) the in the previous posts was actually a collon followed by an upper case p which this lovely forum magically transformed into a smiley.

Share this post


Link to post
Share on other sites
I''ve looked at other languages but the big advantage that python has is I know it already. I''ve looked at lua and didn''t like the way the syntax looked. Haven''t looked at ruby at all.

Share this post


Link to post
Share on other sites
A while ago, somebody said he''d write a tutorial on getting python embedded into a game/engine, but sadly I have not seen such a tutorial yet ...

Before you get to embedding it into a program, I recommend you get used to "extending" it, as you will be doing a lot of that too. Extending python is also much easier than embedding (IMO) and it lets you learn the python/c API without getting lost in the low-level embedding functions. Hopefully soon someone will post a tutorial about it. There are also high-level embedding functions in the API, but they aren''t that flexible really.

Share this post


Link to post
Share on other sites