Storing a lua class with parent in luabind::object

☆樱花仙子☆ 提交于 2019-12-01 20:29:09

This is a known bug in 0.8.1; a reference to the last constructed object is left in the "super" function upvalue. It has been fixed in 0.9-rc1:

http://github.com/luabind/luabind/commit/2c99f0475afea7c282c2e432499fd22aa17744e3

Edit: after OP's update, this answer is no longer relevant, I'll leave it hanging here though. Daniel Wallin posted the correct answer

not really an answer, but I'd lose the formatting with a comment

I cannot reproduce this one. Here's the exact code I use:

// initialization
lua_State* lua = lua_open();
luaL_openlibs(lua);
luabind::open(lua);
// declare class
luaL_loadstring(lua, 
    "class 'TestClass'\
     function TestClass:__init() print('init') end\
     function TestClass:__finalize() print('finalize') end");
lua_pcall(lua, 0, LUA_MULTRET, 0);
// instantiate
{
    luabind::object obj = luabind::call_function<luabind::object>(lua, "TestClass");
}
// collect
printf("Before GC collect\n");
lua_gc(lua, LUA_GCCOLLECT, 0);
printf("After GC collect\n");
lua_close(lua);

And the result I get is:

init
Before GC collect
finalize
After GC collect

I'm using lua 5.1.4, luabind 0.81 with VC8 (aka VS2005) SP1

kFk

Problem is not in luabind::object. It's in class derivation. But problem is not solved yet. Please see corresponding question - Luabind class deriving problem (memory 'leak')

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!