Moved some Lua related string formatting methods from CInterfaceManager to

LuaHelperStuff namespace.
This commit is contained in:
dfighter1985 2012-05-19 00:00:09 +02:00
parent 6e05f7da99
commit 8c33683b6f
7 changed files with 47 additions and 39 deletions

View file

@ -54,7 +54,7 @@ namespace NLMISC{
}
void CCDBManager::delDbNode( const stlpx_std::string &name )
void CCDBManager::delDbNode( const std::string &name )
{
if( name.empty() )
return;

View file

@ -5082,7 +5082,7 @@ NLMISC_COMMAND(luaReload, "reload all .lua script files", "")
}
else
{
pIM->displaySystemInfo(pIM->formatLuaErrorSysInfo(LUADebugNotEnabledMsg));
pIM->displaySystemInfo( LuaHelperStuff::formatLuaErrorSysInfo(LUADebugNotEnabledMsg));
return false;
}
}
@ -5109,7 +5109,7 @@ NLMISC_COMMAND(luaScript, "Execute a lua script", "direct_script_code")
}
else
{
pIM->displaySystemInfo(pIM->formatLuaErrorSysInfo(LUADebugNotEnabledMsg));
pIM->displaySystemInfo( LuaHelperStuff::formatLuaErrorSysInfo(LUADebugNotEnabledMsg));
return false;
}
}
@ -5130,7 +5130,7 @@ NLMISC_COMMAND(luaInfo, "Dump some information on LUA state", "detaillevel from
}
else
{
pIM->displaySystemInfo(pIM->formatLuaErrorSysInfo(LUADebugNotEnabledMsg));
pIM->displaySystemInfo( LuaHelperStuff::formatLuaErrorSysInfo(LUADebugNotEnabledMsg));
return false;
}
}
@ -5142,7 +5142,7 @@ NLMISC_COMMAND(luaObject, "Dump the content of a lua object", "<table name> [max
CInterfaceManager *pIM= CInterfaceManager::getInstance();
if (!ClientCfg.AllowDebugLua)
{
pIM->displaySystemInfo(pIM->formatLuaErrorSysInfo(LUADebugNotEnabledMsg));
pIM->displaySystemInfo( LuaHelperStuff::formatLuaErrorSysInfo(LUADebugNotEnabledMsg));
return false;
}
CLuaState *luaState = pIM->getLuaState();
@ -5189,7 +5189,7 @@ NLMISC_COMMAND(luaGC, "Force a garbage collector of lua", "")
}
else
{
pIM->displaySystemInfo(pIM->formatLuaErrorSysInfo(LUADebugNotEnabledMsg));
pIM->displaySystemInfo( LuaHelperStuff::formatLuaErrorSysInfo(LUADebugNotEnabledMsg));
return false;
}
}

View file

@ -5747,8 +5747,8 @@ bool CInterfaceManager::executeLuaScript(const std::string &luaScript, bool smal
if (sscanf(msg.c_str(), "%s: %s.lua:%d:",exceptionName, filename, &line) == 3) // NB: test not exact here, but should work in 99,9 % of cases
{
msg = CLuaIHM::createGotoFileButtonTag(filename, line) + msg;
nlwarning(formatLuaErrorNlWarn(msg).c_str());
displaySystemInfo(formatLuaErrorSysInfo(msg));
nlwarning(LuaHelperStuff::formatLuaErrorNlWarn(msg).c_str());
displaySystemInfo(LuaHelperStuff::formatLuaErrorSysInfo(msg));
}
else // AJM: handle the other 0.1% of cases
{
@ -5767,8 +5767,8 @@ bool CInterfaceManager::executeLuaScript(const std::string &luaScript, bool smal
else if (line >= 1 && contextList.size() >= line)
msg = error[0]+": \n>>>"+contextList[line-1]+"\nError:"+error[2]+": "+error[3];
}
nlwarning(formatLuaErrorNlWarn(msg).c_str());
displaySystemInfo(formatLuaErrorSysInfo(msg));
nlwarning(LuaHelperStuff::formatLuaErrorNlWarn(msg).c_str());
displaySystemInfo(LuaHelperStuff::formatLuaErrorSysInfo(msg));
}
return false;
}
@ -5785,7 +5785,7 @@ void CInterfaceManager::reloadAllLuaFileScripts()
// if fail to reload a script, display the error code
if(!loadLUA(*it, error))
{
displaySystemInfo(formatLuaErrorSysInfo(error));
displaySystemInfo(LuaHelperStuff::formatLuaErrorSysInfo(error));
}
}
}
@ -5837,25 +5837,11 @@ std::vector<std::string> CInterfaceManager::getInGameXMLInterfaceFiles()
return ret;
}
// ***************************************************************************
void CInterfaceManager::formatLuaStackContext(std::string &stackContext)
{
stackContext= string("@{FC8A}") + stackContext + "@{FC8F} ";
}
std::string CInterfaceManager::formatLuaErrorNlWarn(const std::string &error)
{
// Remove color tags (see formatLuaErrorSC())
std::string ret= error;
strFindReplace(ret, "@{FC8A}", "");
strFindReplace(ret, "@{FC8F}", "");
return ret;
}
// ***************************************************************************
void CInterfaceManager::dumpLuaString(const std::string &str)
{
nlinfo(str.c_str());
displaySystemInfo(formatLuaErrorSysInfo(str));
displaySystemInfo(LuaHelperStuff::formatLuaErrorSysInfo(str));
}
// ***************************************************************************

View file

@ -633,11 +633,6 @@ public:
class CLuaState *getLuaState() const {return _LuaState;}
/// Reload all LUA scripts inserted through <lua>
void reloadAllLuaFileScripts();
/// for Debug: append some color TAG, to have a cool display in SystemInfo
std::string formatLuaErrorSysInfo(const std::string &error) {return std::string("@{FC8F}") + error;}
/// for Debug: append/remove some color TAG, to have a cool display in SystemInfo/nlwarning
void formatLuaStackContext(std::string &stackContext);
std::string formatLuaErrorNlWarn(const std::string &error);
/// For debug: dump in the sysinfo and nlwarning state of lua. detail range from 0 to 2 (clamped).
void dumpLuaState(uint detail);
/// For debug: force a garbage collector

View file

@ -18,7 +18,7 @@
#include "lua_helper.h"
#include "nel/misc/file.h"
#include "interface_manager.h"
//#include "interface_manager.h"
#include "../client_cfg.h"
#ifdef LUA_NEVRAX_VERSION
@ -45,6 +45,28 @@
using namespace std;
using namespace NLMISC;
namespace LuaHelperStuff
{
void formatLuaStackContext( std::string &stackContext )
{
stackContext = std::string( "@{FC8A}" ).append( stackContext ).append( "@{FC8F} " );
}
std::string formatLuaErrorSysInfo( const std::string &error )
{
return std::string( "@{FC8F}" ).append( error );
}
std::string formatLuaErrorNlWarn( const std::string &error )
{
// Remove color tags (see formatLuaErrorSC())
std::string ret = error;
strFindReplace( ret, "@{FC8A}", "" );
strFindReplace( ret, "@{FC8F}", "" );
return ret;
}
}
// ***************************************************************************
const char *CLuaState::_NELSmallScriptTableName= "NELSmallScriptTable";
uint CLuaStackChecker::_ExceptionContextCounter = 0;
@ -706,12 +728,11 @@ void ELuaWrappedFunctionException::init(CLuaState *ls, const std::string &reason
{
//H_AUTO(Lua_ELuaWrappedFunctionException_init)
// Print first Lua Stack Context
CInterfaceManager *pIM= CInterfaceManager::getInstance();
if(ls)
{
ls->getStackContext(_Reason, 1); // 1 because 0 is the current C function => return 1 for script called
// enclose with cool colors
pIM->formatLuaStackContext(_Reason);
LuaHelperStuff::formatLuaStackContext(_Reason);
}
// Append the reason

View file

@ -27,9 +27,16 @@ extern "C"
#include "lua_loadlib.h"
}
class CLuaState;
namespace LuaHelperStuff
{
void formatLuaStackContext( std::string &stackContext );
std::string formatLuaErrorSysInfo( const std::string &error );
std::string formatLuaErrorNlWarn( const std::string &error );
}
// ***************************************************************************
/** Helper class to see if a stack is restored at its initial size (or with n return results).
* Check that the stack size remains unchanged when the object goes out of scope

View file

@ -1806,7 +1806,7 @@ void CLuaIHM::rawDebugInfo(const std::string &dbg)
}
else
{
NLMISC::InfoLog->displayRawNL(pIM->formatLuaErrorSysInfo(dbg).c_str());
NLMISC::InfoLog->displayRawNL(LuaHelperStuff::formatLuaErrorSysInfo(dbg).c_str());
}
#ifdef LUA_NEVRAX_VERSION
if (LuaDebuggerIDE)
@ -1814,7 +1814,7 @@ void CLuaIHM::rawDebugInfo(const std::string &dbg)
LuaDebuggerIDE->debugInfo(dbg.c_str());
}
#endif
pIM->displaySystemInfo(pIM->formatLuaErrorSysInfo(dbg));
pIM->displaySystemInfo( LuaHelperStuff::formatLuaErrorSysInfo(dbg));
}
}
@ -3564,10 +3564,9 @@ bool CLuaIHM::executeFunctionOnStack(CLuaState &ls, int numArgs, int numRet)
int CLuaIHM::breakPoint(CLuaState &ls)
{
//H_AUTO(Lua_CLuaIHM_breakPoint)
CInterfaceManager *pIM= CInterfaceManager::getInstance();
std::string reason;
ls.getStackContext(reason, 1); // 1 because 0 is the current C function => return 1 for script called
pIM->formatLuaStackContext(reason);
LuaHelperStuff::formatLuaStackContext(reason);
NLMISC::InfoLog->displayRawNL(reason.c_str());
static volatile bool doAssert = true;
if (doAssert) // breakPoint can be discarded in case of looping assert