diff --git a/Engine/source/console/console.h b/Engine/source/console/console.h index df921c694..8ac3f2f4c 100644 --- a/Engine/source/console/console.h +++ b/Engine/source/console/console.h @@ -245,7 +245,7 @@ public: if (type == ConsoleValueType::cvSTEntry) return s == StringTable->EmptyString() ? 0 : dAtoi(s); if (type == ConsoleValueType::cvString) - return dStrcmp(s, "") == 0 ? 0 : dAtoi(s); + return dStrcmp(s, "") == 0 ? 0 : dIsdigit(*s) ? dAtoi(s) : s == StringTable->EmptyString() ? 0 : 1; return dAtoi(getConsoleData()); } diff --git a/Engine/source/console/torquescript/CMDscan.cpp b/Engine/source/console/torquescript/CMDscan.cpp index 4497cb961..b533658f0 100644 --- a/Engine/source/console/torquescript/CMDscan.cpp +++ b/Engine/source/console/torquescript/CMDscan.cpp @@ -2827,6 +2827,18 @@ static int Sc_ScanString(int ret) if(!collapseEscape(CMDtext+1)) return -1; + const char* scannedStr = CMDtext + 1; + + if (dStrcmp(scannedStr, "true") == 0) { + CMDlval.i = MakeToken(1, yylineno); + return INTCONST; + } + + if (dStrcmp(scannedStr, "false") == 0) { + CMDlval.i = MakeToken(0, yylineno); + return INTCONST; + } + dsize_t bufferLen = dStrlen( CMDtext ); char* buffer = ( char* ) consoleAlloc( bufferLen ); dStrcpy( buffer, CMDtext + 1, bufferLen ); diff --git a/Engine/source/console/torquescript/CMDscan.l b/Engine/source/console/torquescript/CMDscan.l index aa3a72733..88246a3b5 100644 --- a/Engine/source/console/torquescript/CMDscan.l +++ b/Engine/source/console/torquescript/CMDscan.l @@ -377,6 +377,18 @@ static int Sc_ScanString(int ret) if(!collapseEscape(CMDtext+1)) return -1; + const char* scannedStr = CMDtext + 1; + + if (dStrcmp(scannedStr, "true") == 0) { + CMDlval.i = MakeToken(1, yylineno); + return INTCONST; + } + + if (dStrcmp(scannedStr, "false") == 0) { + CMDlval.i = MakeToken(0, yylineno); + return INTCONST; + } + dsize_t bufferLen = dStrlen( CMDtext ); char* buffer = ( char* ) consoleAlloc( bufferLen ); dStrcpy( buffer, CMDtext + 1, bufferLen ); diff --git a/Engine/source/console/torquescript/astNodes.cpp b/Engine/source/console/torquescript/astNodes.cpp index cc911477d..173f9ab53 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) + { + ip = testExpr->compile(codeStream, ip, TypeReqString); + codeStream.emit(OP_JMPIFNOT); + } + 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..337c71354 100644 --- a/Engine/source/console/torquescript/compiledEval.cpp +++ b/Engine/source/console/torquescript/compiledEval.cpp @@ -1144,6 +1144,7 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi ip++; break; } + ip = code[ip]; break; case OP_JMPIFF: