Merge pull request #1289 from marauder2k9-torque/script-bug-ifstatmt-

if statements
This commit is contained in:
Brian Roberts 2024-06-20 08:45:39 -05:00 committed by GitHub
commit 62f3b93ff9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 40 additions and 5 deletions

View file

@ -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());
}

View file

@ -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)
{

View file

@ -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:

View file

@ -62,6 +62,7 @@ namespace Compiler
OP_JMPIFFNOT,
OP_JMPIFNOT,
OP_JMPNOTSTRING,
OP_JMPIFF,
OP_JMPIF,
OP_JMPIFNOT_NP,

View file

@ -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);