🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

luabind and returning a char*

Started by
0 comments, last by Krun 19 years, 12 months ago
Hi! What would be the correct way of allocating a string when you have to return it in a lua function when using luabind eg. // function that will be exported to lua using luabind const char* f(float id) { char* buffer = new char[100]; sprintf(buffer,"ID = %.0f",id); return buffer; } This would be a memory leak if "buffer" doesn't get deallocated.
Advertisement
Ok. Figured it out. You have to use the "adopt" policie when exporting the function. That way Lua becoms the owner of the string and it is garbage collected when not needed.

This topic is closed to new replies.

Advertisement