- added code to now output all eerors to console (with option to save in log file)

- added more LUA debug info
This commit is contained in:
Mark Vejvoda
2010-10-06 20:22:06 +00:00
parent 268aa4793b
commit 0d050f62d4
36 changed files with 185 additions and 60 deletions

View File

@@ -68,36 +68,49 @@ LuaScript::~LuaScript() {
void LuaScript::loadCode(const string &code, const string &name){
Lua_STREFLOP_Wrapper streflopWrapper;
int errorCode= luaL_loadbuffer(luaState, code.c_str(), code.size(), name.c_str());
if(errorCode!=0){
int errorCode= luaL_loadbuffer(luaState, code.c_str(), code.length(), name.c_str());
if(errorCode !=0 ) {
throw runtime_error("Error loading lua code: " + errorToString(errorCode));
}
//SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] name [%s], errorCode = %d,\ncode [%s]\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),errorCode,code.c_str());
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] name [%s], errorCode = %d\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),errorCode);
//run code
errorCode= lua_pcall(luaState, 0, 0, 0)!=0;
if(errorCode!=0){
errorCode= lua_pcall(luaState, 0, 0, 0);
if(errorCode !=0 ) {
throw runtime_error("Error initializing lua: " + errorToString(errorCode));
}
//SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] name [%s], errorCode = %d,\ncode [%s]\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),errorCode,code.c_str());
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] name [%s], errorCode = %d\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),errorCode);
}
void LuaScript::beginCall(const string& functionName){
Lua_STREFLOP_Wrapper streflopWrapper;
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] functionName [%s]\n",__FILE__,__FUNCTION__,__LINE__,functionName.c_str());
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] functionName [%s]\n",__FILE__,__FUNCTION__,__LINE__,functionName.c_str());
lua_getglobal(luaState, functionName.c_str());
//if( lua_isfunction(luaState,lua_gettop(luaState)) == false) {
// throw runtime_error("Error unknown lua function called: [" + functionName + "]");
//}
argumentCount= 0;
}
void LuaScript::endCall(){
Lua_STREFLOP_Wrapper streflopWrapper;
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
lua_pcall(luaState, argumentCount, 0, 0);
}
void LuaScript::registerFunction(LuaFunction luaFunction, const string &functionName) {
Lua_STREFLOP_Wrapper streflopWrapper;
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] functionName [%s]\n",__FILE__,__FUNCTION__,__LINE__,functionName.c_str());
lua_pushcfunction(luaState, luaFunction);
lua_setglobal(luaState, functionName.c_str());
}