Skip to content

Commit

Permalink
fix float detection in console, fixes stuff like !set type all 0.8C
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Sep 10, 2016
1 parent 86fef64 commit 797f935
Showing 1 changed file with 46 additions and 41 deletions.
87 changes: 46 additions & 41 deletions src/lua/TPTScriptInterface.cpp
Expand Up @@ -80,48 +80,53 @@ ValueType TPTScriptInterface::testType(std::string word)
return TypeFunction;
else if (word == "quit")
return TypeFunction;

//Basic type
for (i = 0; i < word.length(); i++)
{
if (!(rawWord[i] >= '0' && rawWord[i] <= '9') && !(rawWord[i] == '-' && !i))
{
if (rawWord[i] == '.' && rawWord[i+1])
goto parseFloat;
else if (rawWord[i] == ',' && rawWord[i+1] >= '0' && rawWord[i+1] <= '9')
goto parsePoint;
else if ((rawWord[i] == '#' || (i && rawWord[i-1] == '0' && rawWord[i] == 'x')) &&
((rawWord[i+1] >= '0' && rawWord[i+1] <= '9')
|| (rawWord[i+1] >= 'a' && rawWord[i+1] <= 'f')
|| (rawWord[i+1] >= 'A' && rawWord[i+1] <= 'F')))
goto parseNumberHex;
else
goto parseString;
}
}
return TypeNumber;
parseFloat:
for (i++; i < word.length(); i++)
if (!((rawWord[i] >= '0' && rawWord[i] <= '9') || (rawWord[i] >= 'a' && rawWord[i] <= 'f') || (rawWord[i] >= 'A' && rawWord[i] <= 'F')))
{
goto parseString;
}
return TypeFloat;
parseNumberHex:
for (i++; i < word.length(); i++)
if (!((rawWord[i] >= '0' && rawWord[i] <= '9') || (rawWord[i] >= 'a' && rawWord[i] <= 'f') || (rawWord[i] >= 'A' && rawWord[i] <= 'F')))
{
goto parseString;
}
return TypeNumber;
parsePoint:
for (i++; i < word.length(); i++)
if (!(rawWord[i] >= '0' && rawWord[i] <= '9'))
{
goto parseString;
}
return TypePoint;
parseString:
return TypeString;
for (i = 0; i < word.length(); i++)
{
if (!(rawWord[i] >= '0' && rawWord[i] <= '9') && !(rawWord[i] == '-' && !i))
{
if (rawWord[i] == '.' && rawWord[i+1])
goto parseFloat;
else if (rawWord[i] == ',' && rawWord[i+1] >= '0' && rawWord[i+1] <= '9')
goto parsePoint;
else if ((rawWord[i] == '#' || (i && rawWord[i-1] == '0' && rawWord[i] == 'x')) &&
((rawWord[i+1] >= '0' && rawWord[i+1] <= '9')
|| (rawWord[i+1] >= 'a' && rawWord[i+1] <= 'f')
|| (rawWord[i+1] >= 'A' && rawWord[i+1] <= 'F')))
goto parseNumberHex;
else
goto parseString;
}
}
return TypeNumber;

parseFloat:
for (i++; i < word.length(); i++)
if (!((rawWord[i] >= '0' && rawWord[i] <= '9')))
{
goto parseString;
}
return TypeFloat;

parseNumberHex:
for (i++; i < word.length(); i++)
if (!((rawWord[i] >= '0' && rawWord[i] <= '9') || (rawWord[i] >= 'a' && rawWord[i] <= 'f') || (rawWord[i] >= 'A' && rawWord[i] <= 'F')))
{
goto parseString;
}
return TypeNumber;

parsePoint:
for (i++; i < word.length(); i++)
if (!(rawWord[i] >= '0' && rawWord[i] <= '9'))
{
goto parseString;
}
return TypePoint;

parseString:
return TypeString;
}

int TPTScriptInterface::parseNumber(char * stringData)
Expand Down

0 comments on commit 797f935

Please sign in to comment.