//Makes the SceneManager object available to all Lua scripts.
luabind::globals(LuaInterfaceManager::LuaManager)["SceneManager"] = SceneMgr;
//Makes the UIScene available to all Lua scripts.
luabind::module(LuaInterfaceManager::LuaManager)[luabind::class_<UIScene>("UIScene").def(
luabind::constructor<SceneManager, std::string>()).def("LoadBackground", &UIScene::LoadBackground)];
I'm not exactly sure why, but they both make LuaBind crash horribly. I tried commenting out each of them in turn, and they both cause a crash.
Does you have other bindings in your code that do work? Is it crashing when the binding code is executing, or when the bound code is being called from within Lua? Are you making sure that ownership of bound objects is being handled correctly? (Ie, Lua isn't using its automatic garbage collection on your engine manager objects is it?)
I don't see anything wrong after a cursory glance. Here's some equivalent code from Allacrost that achieves the same effect (and works):
or when the bound code is being called from within Lua? Are you making sure that ownership of bound objects is being handled correctly? (Ie, Lua isn't using its automatic garbage collection on your engine manager objects is it?)[/quote]
[color="#1C2837"]
[color="#1C2837"]Nope. I'm not even running any Lua code as of yet.
IIRC
LuaInterfaceManager::LuaManager is not a part of LuaBind , i'm guessing that this is your Lua State though.
I had a similar crash that was caused by me not calling luabind::open(myownluastate); before i used luabind::module.
You should also create your lua state using lua_open (and close it using lua_close)
Thus you want to do:
lua_State *L = lua_open();
luabind::open(L);
...
luabind::module(L) ....
not calling luabind::open will result in a segmentation fault.
(If you recieve your lua state from the lua runtime you don't have to create your lua state using lua_open() but you still have to call luabind::open on it)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Yeah I fixed it!
I had put lua_open() and luabin::open() inside the constructor for LuaInterfaceManager. I assumed that I had made LuaInterfaceManager static and that the constructor was calling itself, but then I realized that static classes aren't even allowed in C++. :\ So I had to call the constructor manually.
Ok so after fiddling around I've gotten logging to work.
Lua reports:
scenemanager.cpp (00011): , [SceneManager::LoadInitialScreen], [s_0] [Mon May 16 18:18:16 2011], Error encountered in Lua script: gamedata\luascripts\personselection.lua:6: attempt to call global 'UIScreen' (a nil value)
And here is the function I made to register classes:
//Registers all neccessary classes so that they are available to use
//when scripting in Lua.
void LuaInterfaceManager::RegisterClasses()
{
//Make the SceneManager class available to Lua.
luabind::module(LuaInterfaceManager::LuaManager)
[luabind::class_<SceneManager>("SceneManager")
.def(
luabind::constructor<>())
.def("LoadInitialScreen", &SceneManager::LoadInitialScreen)];
//Makes the UIScene class available to all Lua scripts.
luabind::module(LuaInterfaceManager::LuaManager)
[luabind::class_<UIScene>("UIScene")
.def(luabind::constructor<std::string>())
.def("LoadBackground", &UIScene::LoadBackground)];
}
Ok so after fiddling around I've gotten logging to work.
Lua reports:
scenemanager.cpp (00011): , [SceneManager::LoadInitialScreen], [s_0] [Mon May 16 18:18:16 2011], Error encountered in Lua script: gamedata\luascripts\personselection.lua:6: attempt to call global 'UIScreen' (a nil value)
And here is the function I made to register classes:
//Registers all neccessary classes so that they are available to use
//when scripting in Lua.
void LuaInterfaceManager::RegisterClasses()
{
//Make the SceneManager class available to Lua.
luabind::module(LuaInterfaceManager::LuaManager)
[luabind::class_<SceneManager>("SceneManager")
.def(
luabind::constructor<>())
.def("LoadInitialScreen", &SceneManager::LoadInitialScreen)];
//Makes the UIScene class available to all Lua scripts.
luabind::module(LuaInterfaceManager::LuaManager)
[luabind::class_<UIScene>("UIScene")
.def(luabind::constructor<std::string>())
.def("LoadBackground", &UIScene::LoadBackground)];
}
Help!
Nvm, looks like it was a typo, Roots caught it.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!