[Lua] Resolve stoi Exception (#2736)

* [Lua] Resolve stoi Exception

* Change fallback for wp, not really needed for safety

* Change to Strings::ToInt
This commit is contained in:
Chris Miles
2023-02-06 17:22:01 -06:00
committed by GitHub
parent 8031bf0bcb
commit 6a9228ed6e
3 changed files with 102 additions and 94 deletions
+7
View File
@@ -763,3 +763,10 @@ std::string Strings::Random(size_t length)
std::generate_n(str.begin(), length, randchar);
return str;
}
// a wrapper for stoi which will return a fallback if the string
// fails to cast to a number
int Strings::ToInt(const std::string &s, int fallback)
{
return Strings::IsNumber(s) ? std::stoi(s) : fallback;
}