I've got a slight problem with LuaBind, and lack of experiance with the system has got me kinda stumped.
I've a bit of program which needs to be changed often and so i thought, aha! perfect for some scripting
![](smile.gif)
So, i set about recrafting it in Lua5.0 and LuaBind and everything compiles fine however i'm getting a runtime error and i dont understand why, i've probably missed something simple knowing my luck :o
I'm setting up Lua and LuaBind thusly
void Init_Lua(lua_State * &luaVM)
{
luaVM = lua_open();
lua_baselibopen(luaVM);
luabind::open(luaVM);
// register in the function to create the new instances of the classes
luabind::function(luaVM,"NewHLBased",&ParserMakers::NewHLBased);
luabind::function(luaVM,"NewQuakeWorldBased",&ParserMakers::NewQuakeWorldBased);
luabind::function(luaVM,"NewQuake2Based",&ParserMakers::NewQuake2Based);
luabind::function(luaVM,"NewQuake3Based",&ParserMakers::NewQuake3Based);
luabind::function(luaVM,"NewBF1942Based",&ParserMakers::NewBF1942Based);
luabind::function(luaVM,"NewAAOBased",&ParserMakers::NewAAOBased);
luabind::function(luaVM,"NewStandardBased",&ParserMakers::NewStandardBased);
luabind::function(luaVM,"NewAltStandardBased",&ParserMakers::NewAltStandardBased);
luabind::function(luaVM,"NewUnrealBased",&ParserMakers::NewUnrealBased);
luabind::class_<utility::serverdetails>(luaVM,"serverdetails");
luabind::class_<MicroThreadSystem::MicroThread>(luaVM,"Microthread");
luabind::class_<MicroThreadSystem::MicroThreadMgr>(luaVM,"MicrothreadMgr");
luabind::class_<Parsers::parsermarkers>(luaVM,"parsermarkers");
MakeParser = luabind::functor<MicroThreadSystem::MicroThread*>(luaVM,"GetParser"); // Get a function object of the Parser maker (function object is declared extern in a header file and included in this file as part of the ParserMaker namespace
lua_dofile(luaVM, "pingservers.lua");
}
All the above function pointers point to functions which exist within the cpp file and everything seems to go off without a problem, lua inits (i see some debug txt i put at the top of the file) with no parsing errors.
Then i come to use the functor I bound above :
MicroThreadSystem::t_MTPTR NewParser(utility::serverdetails &details, MicroThreadSystem::MicroThreadMgr * parent)
{
MicroThreadSystem::t_MTPTR parser;
// parser.reset(ParserMakers::NewHLBased(details, parent));
parser.reset(static_cast<MicroThreadSystem::MicroThread*>(ParserMakers::MakeParser(details,parent)));
return parser;
}
Its during the various calls to functions in the LuaBind Functor object i get an exception thrown :
typename default_policy::template generate_converter<Ret, lua_to_cpp>::type converter;
m_called = true;
lua_State* L = m_func->lua_state();
detail::stack_pop p(L, 1); // pop the return value
// get the function
m_func->pushvalue();
push_args_from_tuple<1>::apply(L, m_args);
if (lua_pcall(L, boost::tuples::length<Tuple>::value, 1, 0))
{
#ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L); // error comes from there
#else
error_callback_fun e = detail::error_callback::get().err;
if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
"if you want to handle this error use luabind::set_error_callback()");
std::terminate();
#endif
}
I've done the normal debug stuff, the tuple contains a valid copy of the data I want to be passed to Lua and the Lua state is set fine.
Extra info that might be needed :
MicroThreadSystem::t_MTPTR is a Boost::shared_ptr to a MicroThreadSystem::MicroThread object, base class which all the other parser object derive from.
MicroThreadSystem::MicroThreadMgr controls a set of MicroThreads
utility::serverdetails is a struct containing a string and 2 ints
Parsers:: parsermarkers is a struct containing std::strings only
Small sample of the Lua Script its calling :
function GetParser(details,parent)
print("Entering GetParser")
markers = parsermarkers();
if details.gameid == GAME_UNREAL
or details.gameid == GAME_UT
or details.gameid == GAME_UT2K3
or details.gameid == GAME_U2
then
markers.name = "\\player_"
markers.nameend = "\\frags_"
markers.score1 = "\\frags_"
markers.score1end = "\\ping_"
return NewUnrealBased(details,parent,markers)
end
end
Note: "Entering GetParser" is never displayed
[edited by - _the_phantom_ on January 22, 2004 12:50:22 PM]