diff --git a/Engine/source/console/console.h b/Engine/source/console/console.h index df921c694..b3163e5c5 100644 --- a/Engine/source/console/console.h +++ b/Engine/source/console/console.h @@ -246,6 +246,7 @@ public: return s == StringTable->EmptyString() ? 0 : dAtoi(s); if (type == ConsoleValueType::cvString) return dStrcmp(s, "") == 0 ? 0 : dAtoi(s); + return dAtoi(getConsoleData()); } diff --git a/Engine/source/console/torquescript/astNodes.cpp b/Engine/source/console/torquescript/astNodes.cpp index cc911477d..17d96c961 100644 --- a/Engine/source/console/torquescript/astNodes.cpp +++ b/Engine/source/console/torquescript/astNodes.cpp @@ -200,7 +200,9 @@ U32 IfStmtNode::compileStmt(CodeStream& codeStream, U32 ip) U32 endifIp, elseIp; addBreakLine(codeStream); - if (testExpr->getPreferredType() == TypeReqUInt) + TypeReq testType = testExpr->getPreferredType(); + + if (testType == TypeReqUInt) { integer = true; } @@ -209,8 +211,16 @@ U32 IfStmtNode::compileStmt(CodeStream& codeStream, U32 ip) integer = false; } - ip = testExpr->compile(codeStream, ip, integer ? TypeReqUInt : TypeReqFloat); - codeStream.emit(integer ? OP_JMPIFNOT : OP_JMPIFFNOT); + if (testType == TypeReqString || testType == TypeReqNone) + { + ip = testExpr->compile(codeStream, ip, TypeReqString); + codeStream.emit(OP_JMPNOTSTRING); + } + else + { + ip = testExpr->compile(codeStream, ip, integer ? TypeReqUInt : TypeReqFloat); + codeStream.emit(integer ? OP_JMPIFNOT : OP_JMPIFFNOT); + } if (elseBlock) { diff --git a/Engine/source/console/torquescript/compiledEval.cpp b/Engine/source/console/torquescript/compiledEval.cpp index 3d765c470..94ddcab80 100644 --- a/Engine/source/console/torquescript/compiledEval.cpp +++ b/Engine/source/console/torquescript/compiledEval.cpp @@ -1144,6 +1144,15 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi ip++; break; } + + ip = code[ip]; + break; + case OP_JMPNOTSTRING: + if (stack[_STK--].getBool()) + { + ip++; + break; + } ip = code[ip]; break; case OP_JMPIFF: diff --git a/Engine/source/console/torquescript/compiler.h b/Engine/source/console/torquescript/compiler.h index e1cfbbed9..74737c773 100644 --- a/Engine/source/console/torquescript/compiler.h +++ b/Engine/source/console/torquescript/compiler.h @@ -62,6 +62,7 @@ namespace Compiler OP_JMPIFFNOT, OP_JMPIFNOT, + OP_JMPNOTSTRING, OP_JMPIFF, OP_JMPIF, OP_JMPIFNOT_NP, diff --git a/Engine/source/core/strings/stringFunctions.h b/Engine/source/core/strings/stringFunctions.h index d0c91b734..d1556f7a6 100644 --- a/Engine/source/core/strings/stringFunctions.h +++ b/Engine/source/core/strings/stringFunctions.h @@ -259,9 +259,23 @@ extern S32 dStrcmp(const UTF16 *str1, const UTF16 *str2); extern S32 dStrnatcmp( const char* str1, const char* str2 ); extern S32 dStrnatcasecmp( const char* str1, const char* str2 ); -inline bool dAtob(const char *str) +inline bool dAtob(const char* str) { - return !dStricmp(str, "true") || dAtof(str); + if (str && str[0] != '\0') + { + if (dStricmp(str, "0") == 0) + return false; + if (dStricmp(str, "0.0") == 0) + return false; + if (dStricmp(str, "0.0f") == 0) + return false; + if (dStricmp(str, "null") == 0) + return false; + if (dStricmp(str, "false") == 0) + return false; + return true; + } + return false; } bool dStrEqual(const char* str1, const char* str2);