sol2
sol2 copied to clipboard
Is there a way to get 'pre-formatted' error message & line number?
From a sol::protected_function_result, I do the following to check for, and get error messages:
if (!result.valid())
{
sol::error err = result;
std::cout << err.what() << std::endl;
}
This gives a nicely formatted message such as:
[string "..."]:3: '(' expected near 'foo'
What I'm wondering is if it's possible to get (from either the protected_function_result
, or from the error
, or from some other object) the line number (3
) and the error message '(' expected near 'foo'
separately? The main purpose for this is to highlight the line where the error occurs in an embedded script window, so preferably the number would come as a int type rather than a string type. If there is nothing built-in to sol I can of course extract the line number with regex, but I wanted to first check if there is a neater solution
To me the error looks like normal lua error, which is formatted by lua and sol just captures the final string and gives it to you. So unless you modify/tap into the error handling of lua I suspect you would not be able to get the parts separately.