mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-22 04:37:13 +01:00
Move line retrieval into the script wrapper.
Might be used elsewhere.
This commit is contained in:
parent
d6a3937107
commit
acea3db378
@ -174,4 +174,25 @@ ScriptSrc::ScriptSrc(HSQUIRRELVM vm, String && path, bool delay, bool info)
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
String ScriptSrc::FetchLine(size_t line, bool trim) const
|
||||
{
|
||||
// Do we have such line?
|
||||
if (line > mLine.size())
|
||||
{
|
||||
return String(); // Nope!
|
||||
}
|
||||
// Grab it's range in the file
|
||||
Line::const_reference l = mLine.at(line);
|
||||
// Grab the code from that line
|
||||
String code = mData.substr(l.first, l.second - l.first);
|
||||
// Trim whitespace from the beginning of the code code
|
||||
if (trim)
|
||||
{
|
||||
code.erase(0, code.find_first_not_of(" \t\n\r\f\v"));
|
||||
}
|
||||
// Return the resulting string
|
||||
return code;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -71,6 +71,10 @@ public:
|
||||
*/
|
||||
ScriptSrc & operator = (ScriptSrc && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Fetches a line from the code. Can also triim whitespace at the beginning.
|
||||
*/
|
||||
String FetchLine(size_t line, bool trim = true) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -903,12 +903,8 @@ bool Core::CompilerErrorHandlerEx(CSStr desc, CSStr src, SQInteger line, SQInteg
|
||||
{
|
||||
return false; // No such line!
|
||||
}
|
||||
// Grab the line we're looking for
|
||||
ScriptSrc::Line::iterator itr = script->mLine.begin() + line;
|
||||
// Grab the code from that line
|
||||
String code = script->mData.substr(itr->first, itr->second - itr->first);
|
||||
// Trim whitespace from the beginning of the code code
|
||||
code.erase(0, code.find_first_not_of(" \t\n\r\f\v"));
|
||||
// Grab the associated line of code
|
||||
String code = script->FetchLine(line, true);
|
||||
// Display the error message with the code included
|
||||
LogFtl("Message: %s\n[\n=>Location: %s\n=>Line: %" PRINT_SZ_FMT "\n=>Column: %" PRINT_INT_FMT "\n=>Code: %s\n]", desc, src, ++line, column, code.c_str());
|
||||
// We displayed the information
|
||||
|
Loading…
x
Reference in New Issue
Block a user