Jump to content
  • Advertisement
Sign in to follow this  
Jnz86

Lua, Python

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, last few days i was reading Python documentation and learning Python, and when time came to embbed(right word?) it into my app i find it very anoying with all these DECREF,INCREF . So i want to ask for advice, someone who tried both Lua and Python, IS LUA RELLY EASIER TO INTEGRATE INTO APP THAN PYTHON ?(if it is i think i will learn Lua, and drop Python...). Do i need to keep track of objects in Lua like in Python with DECREF and so on... Thanks...

Share this post


Link to post
Share on other sites
Advertisement
If you chose not to use an integration library than Lua is hands-down easier to embed than Python. If you choose to use an integration library like toLua or boost::python then they're about the same.

Share this post


Link to post
Share on other sites
Quote:
and when time came to embbed(right word?) it into my app i find it very anoying with all these DECREF,INCREF


Yes, that's embedding. No, it's not trivial. Using boost::python, SWIG or even Elmer make it much simpler.

Quote:
Do i need to keep track of objects in Lua like in Python with DECREF and so on...


Skimming the manual, apparently not. The price you pay is that Lua is not aware of references that exist on the C side of your application, so you may end up with dangling pointers.

Share this post


Link to post
Share on other sites
Quote:

If you chose not to use an integration library than Lua is hands-down easier to embed than Python. If you choose to use an integration library like toLua or boost::python then they're about the same.

if i use boost::python, do i have to deal with reference counting ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Jnz86
if i use boost::python, do i have to deal with reference counting ?


Not directly, no. The object constructor and destructor take care of incrementing and decrementing the reference count. A wrapper exist to take care of "borrowed references". You just have to make sure you do capture any stray PyObject*

From the tutorial:

object main_module((
handle<>(borrowed(PyImport_AddModule("__main__")))));

object main_namespace = main_module.attr("__dict__");

handle<> ignored((PyRun_String(

"hello = file('hello.txt', 'w')\n"
"hello.write('Hello world!')\n"
"hello.close()"

, Py_file_input
, main_namespace.ptr()
, main_namespace.ptr())
));


PyImport_AddModule returns a borrowed reference that we need, so we wrap it with borrowed. PyRun_String returns a new reference that we don't need, so we store it in an object variable and just do nothing with it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jnz86
Well i look into boost::python, it's a life saver i guess :)
Thanks guys!


It's not perfect but it helps a lot. It's definitely not as simple as if there were no reference counting at all.

Share this post


Link to post
Share on other sites
Do you recall if the Python spec requires reference counting or is it a C/Python implementation detail?

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
If you want to use boost::python, you might want to check out my draft article on setting up projects with boost::python. There are a few details that can screw you up when setting up boost::python like forgetting to enable RTTI.

I will look at that. Thanks again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!