support floats in the console
There are some strange bugs with parsing like !set type all 3.5 or !set temp all moo but they aren't too important ...
This commit is contained in:
parent
859fdece6a
commit
ccb3de7365
@ -86,12 +86,12 @@ AnyType::~AnyType()
|
||||
|
||||
//Number Type
|
||||
|
||||
NumberType::NumberType(int number): AnyType(TypeNumber, ValueValue())
|
||||
NumberType::NumberType(float number): AnyType(TypeNumber, ValueValue())
|
||||
{
|
||||
value.num = number;
|
||||
}
|
||||
|
||||
int NumberType::Value()
|
||||
float NumberType::Value()
|
||||
{
|
||||
return value.num;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "gui/interface/Point.h"
|
||||
|
||||
enum ValueType { TypeNumber, TypePoint, TypeString, TypeNull, TypeFunction };
|
||||
typedef union { int num; std::string* str; ui::Point* pt; } ValueValue;
|
||||
typedef union { float num; std::string* str; ui::Point* pt; } ValueValue;
|
||||
|
||||
class GeneralException
|
||||
{
|
||||
@ -91,8 +91,8 @@ public:
|
||||
class NumberType: public AnyType
|
||||
{
|
||||
public:
|
||||
NumberType(int number);
|
||||
int Value();
|
||||
NumberType(float number);
|
||||
float Value();
|
||||
};
|
||||
|
||||
class StringType: public AnyType
|
||||
|
@ -117,7 +117,7 @@ ValueType TPTScriptInterface::testType(std::string word)
|
||||
return TypeString;
|
||||
}
|
||||
|
||||
int TPTScriptInterface::parseNumber(char * stringData)
|
||||
float TPTScriptInterface::parseNumber(char * stringData)
|
||||
{
|
||||
char cc;
|
||||
int base = 10;
|
||||
@ -257,7 +257,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
||||
throw GeneralException("Invalid property");
|
||||
|
||||
//Selector
|
||||
int newValue;
|
||||
float newValue;
|
||||
if(value.GetType() == TypeNumber)
|
||||
{
|
||||
newValue = ((NumberType)value).Value();
|
||||
@ -268,9 +268,9 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
||||
{
|
||||
std::string newString = ((StringType)value).Value();
|
||||
if (newString.at(newString.length()-1) == 'C')
|
||||
newValue = atoi(newString.substr(0, newString.length()-1).c_str())+273;
|
||||
newValue = atof(newString.substr(0, newString.length()-1).c_str())+273.15;
|
||||
else if (newString.at(newString.length()-1) == 'F')
|
||||
newValue = (int)((atoi(newString.substr(0, newString.length()-1).c_str())-32.0f)*5/9+273.15f);
|
||||
newValue = (atof(newString.substr(0, newString.length()-1).c_str())-32.0f)*5/9+273.15f;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
class TPTScriptInterface: public CommandInterface {
|
||||
protected:
|
||||
AnyType eval(std::deque<std::string> * words);
|
||||
int parseNumber(char * stringData);
|
||||
float parseNumber(char * stringData);
|
||||
AnyType tptS_set(std::deque<std::string> * words);
|
||||
AnyType tptS_create(std::deque<std::string> * words);
|
||||
AnyType tptS_delete(std::deque<std::string> * words);
|
||||
|
Loading…
Reference in New Issue
Block a user