Advertisement

luabind and returning a char*

Started by July 11, 2004 06:39 AM
0 comments, last by Krun 20 years, 4 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.
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