Merge pull request #2539 from Capostrophic/scripting

Try to parse strings as number literals (bug #5097)
This commit is contained in:
Roman Siromakha 2019-10-24 22:12:50 +02:00 committed by GitHub
commit 4e5aec5c30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View file

@ -5,6 +5,7 @@
#include <algorithm>
#include <stack>
#include <iterator>
#include <sstream>
#include <components/misc/stringops.hpp>
@ -324,6 +325,21 @@ namespace Compiler
mExplicit = name2;
return true;
}
// This is terrible, but of course we must have this for legacy content.
// Convert the string to a number even if it's impossible and use it as a number literal.
// Can't use stof/atof or to_string out of locale concerns.
float number;
std::stringstream stream(name2);
stream >> number;
stream.str(std::string());
stream.clear();
stream << number;
pushFloatLiteral(number);
mTokenLoc = loc;
getErrorHandler().warning ("Parsing a non-variable string as a number: " + stream.str(), loc);
return true;
}
else
{