【发布时间】:2016-04-15 14:50:43
【问题描述】:
有没有办法将在堆上分配的对象返回到 lua 而不“缓存”对它们的引用?
考虑以下几点:
class foo
{
char const* bar() const
{
char* s = malloc(...);
...
return s; // << Leak. How to transfer the ownership of 's' to lua?
}
};
如果我向分配的内存返回一个字符串,我必须删除它。 有没有办法将所有权转移给lua?
或者甚至有可能让lua_state*使用lua_pushstring(...)实现我自己返回的字符串?
【问题讨论】: