mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 18:09:39 +00:00
reset errorhandler context
This commit is contained in:
parent
2a31382e20
commit
8958e29187
3 changed files with 29 additions and 3 deletions
|
@ -171,7 +171,7 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
Compiler::Locals locals;
|
Compiler::Locals locals;
|
||||||
|
|
||||||
mErrorHandler.setContext(name2 + "[local variables]");
|
Compiler::ContextRestore restore = mErrorHandler.setContext(name2 + "[local variables]", true);
|
||||||
|
|
||||||
std::istringstream stream (script->mScriptText);
|
std::istringstream stream (script->mScriptText);
|
||||||
Compiler::QuickFileParser parser (mErrorHandler, mCompilerContext, locals);
|
Compiler::QuickFileParser parser (mErrorHandler, mCompilerContext, locals);
|
||||||
|
|
|
@ -56,10 +56,25 @@ namespace Compiler
|
||||||
Log(logLevel) << text.str();
|
Log(logLevel) << text.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamErrorHandler::setContext(const std::string &context)
|
ContextRestore StreamErrorHandler::setContext(const std::string &context, bool restore)
|
||||||
{
|
{
|
||||||
|
if (!restore)
|
||||||
|
{
|
||||||
|
mContext = context;
|
||||||
|
return {nullptr, {}};
|
||||||
|
}
|
||||||
|
ContextRestore restorer(this, mContext);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
return restorer;
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamErrorHandler::StreamErrorHandler() {}
|
StreamErrorHandler::StreamErrorHandler() {}
|
||||||
|
|
||||||
|
ContextRestore::ContextRestore(StreamErrorHandler* handler, const std::string& context) : mHandler(handler), mContext(context) {}
|
||||||
|
|
||||||
|
ContextRestore::~ContextRestore()
|
||||||
|
{
|
||||||
|
if(mHandler)
|
||||||
|
mHandler->setContext(mContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
{
|
{
|
||||||
|
class ContextRestore;
|
||||||
/// \brief Error handler implementation: Write errors into logging stream
|
/// \brief Error handler implementation: Write errors into logging stream
|
||||||
|
|
||||||
class StreamErrorHandler : public ErrorHandler
|
class StreamErrorHandler : public ErrorHandler
|
||||||
|
@ -26,13 +27,23 @@ namespace Compiler
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void setContext(const std::string& context);
|
ContextRestore setContext(const std::string& context, bool restore = false);
|
||||||
|
|
||||||
// constructors
|
// constructors
|
||||||
|
|
||||||
StreamErrorHandler ();
|
StreamErrorHandler ();
|
||||||
///< constructor
|
///< constructor
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ContextRestore
|
||||||
|
{
|
||||||
|
StreamErrorHandler* mHandler;
|
||||||
|
const std::string mContext;
|
||||||
|
public:
|
||||||
|
ContextRestore (StreamErrorHandler* handler, const std::string& context);
|
||||||
|
|
||||||
|
~ContextRestore();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue