从 C++ 返回对象表,采用策略
使用 luabind,我从 C++ 创建一个对象表,
luabind::object create_table(lua_State *L)
{
luabind::object result = luabind::newtable(L);
int index = 1;
for ( ... ) {
lua_Object *o = new lua_Object( ... );
result[ index ++ ] = o;
}
return result;
}
我将函数注册为
module(L)
[
def("create_table", &create_table)
]
lua_Object 为
class_<lua_Object> reg("Object");
reg
.def(constructor<float,float>())
;
module(L) [ reg ];
如何告诉 luabind 获取表中存储的对象的所有权( new lua_Object( ... ) )?有什么解决方法吗?
谢谢 -
Using luabind, I create a table of objects from C++
luabind::object create_table(lua_State *L)
{
luabind::object result = luabind::newtable(L);
int index = 1;
for ( ... ) {
lua_Object *o = new lua_Object( ... );
result[ index ++ ] = o;
}
return result;
}
I register the function as
module(L)
[
def("create_table", &create_table)
]
and lua_Object as
class_<lua_Object> reg("Object");
reg
.def(constructor<float,float>())
;
module(L) [ reg ];
How can I tell luabind to take ownership of the objects stored in the table ( new lua_Object( ... ) )? What would be a work around?
Thanks -
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
替换
为
顺便说一句,您是否必须使用
raw(_1)
策略注册create_table
?Replace
with
On a side note, don't you have to register
create_table
withraw(_1)
policy?