Odd Problem with luabind::object
I'm currently using luabind, specifically https://github.com/rpavlik/luabind since the official release is outdated and doesn't compile with the latest version of boost anymore.
I'm getting a very odd problem that I can't find anywhere on the net. I managed to reduce the case to a very simple scenario.
In one module I will have:
luabind::object value;
void functionA() {
lua_pushstring(L,"yo");
luabind::object temp(luabind::from_stack(L,-1));
value = temp;
}
In another module I will have:
void functionB() {
printf("My Value: %s\n",luabind::object_cast<const char*>(value));
printf("My Original value type: %d\n",luabind::type(value));
value.push(L);
luabind::object a1(luabind::from_stack(L,-1));
printf("My Copy value type: %d\n",luabind::type(a1));
}
When I make functionA and functionB available from lua and call them in succession, the output will be:
My Value: yo
My Original value type: 4
My Copy value type: 0
As you can see, the object still references something that luabind can print. But when I try to push it on the stack and create a new object from the stack object, it will result in a nil value.
This only happens in this specific case. When I put everything into one function, it works fine. When I put the code into functions of the same module, it'll work fine. I haven't made a standalone test project yet, but I can't think of anything in my code interferring, the functions are called in direct succession from lua.
Am I doing something wrong? Or is this a bug? And if 开发者_StackOverflow中文版it's a bug, how come I've never heard of something like this?
It seems my test case was incomplete. functionB also needs to be in a class wrapped by luabind. I could "resolve" the issue by making the function in the class a proxy function, and calling a global function containing my code from there.
精彩评论