mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 00:54:54 +00:00
if statements
Changed: if check on vals now return true if the value has a string value %val = "test me" if(%val) will now return true since %val is not null Script side: string checks for "true" and "false" will now be parsed as integer values of 1 and 0. TEST VIGOUROUSLY
This commit is contained in:
parent
760c153232
commit
e56f4cb6a6
5 changed files with 39 additions and 4 deletions
|
|
@ -245,7 +245,7 @@ public:
|
||||||
if (type == ConsoleValueType::cvSTEntry)
|
if (type == ConsoleValueType::cvSTEntry)
|
||||||
return s == StringTable->EmptyString() ? 0 : dAtoi(s);
|
return s == StringTable->EmptyString() ? 0 : dAtoi(s);
|
||||||
if (type == ConsoleValueType::cvString)
|
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());
|
return dAtoi(getConsoleData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2827,6 +2827,18 @@ static int Sc_ScanString(int ret)
|
||||||
if(!collapseEscape(CMDtext+1))
|
if(!collapseEscape(CMDtext+1))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
const char* scannedStr = CMDtext + 1;
|
||||||
|
|
||||||
|
if (dStrcmp(scannedStr, "true") == 0) {
|
||||||
|
CMDlval.i = MakeToken<int>(1, yylineno);
|
||||||
|
return INTCONST;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dStrcmp(scannedStr, "false") == 0) {
|
||||||
|
CMDlval.i = MakeToken<int>(0, yylineno);
|
||||||
|
return INTCONST;
|
||||||
|
}
|
||||||
|
|
||||||
dsize_t bufferLen = dStrlen( CMDtext );
|
dsize_t bufferLen = dStrlen( CMDtext );
|
||||||
char* buffer = ( char* ) consoleAlloc( bufferLen );
|
char* buffer = ( char* ) consoleAlloc( bufferLen );
|
||||||
dStrcpy( buffer, CMDtext + 1, bufferLen );
|
dStrcpy( buffer, CMDtext + 1, bufferLen );
|
||||||
|
|
|
||||||
|
|
@ -377,6 +377,18 @@ static int Sc_ScanString(int ret)
|
||||||
if(!collapseEscape(CMDtext+1))
|
if(!collapseEscape(CMDtext+1))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
const char* scannedStr = CMDtext + 1;
|
||||||
|
|
||||||
|
if (dStrcmp(scannedStr, "true") == 0) {
|
||||||
|
CMDlval.i = MakeToken<int>(1, yylineno);
|
||||||
|
return INTCONST;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dStrcmp(scannedStr, "false") == 0) {
|
||||||
|
CMDlval.i = MakeToken<int>(0, yylineno);
|
||||||
|
return INTCONST;
|
||||||
|
}
|
||||||
|
|
||||||
dsize_t bufferLen = dStrlen( CMDtext );
|
dsize_t bufferLen = dStrlen( CMDtext );
|
||||||
char* buffer = ( char* ) consoleAlloc( bufferLen );
|
char* buffer = ( char* ) consoleAlloc( bufferLen );
|
||||||
dStrcpy( buffer, CMDtext + 1, bufferLen );
|
dStrcpy( buffer, CMDtext + 1, bufferLen );
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,9 @@ U32 IfStmtNode::compileStmt(CodeStream& codeStream, U32 ip)
|
||||||
U32 endifIp, elseIp;
|
U32 endifIp, elseIp;
|
||||||
addBreakLine(codeStream);
|
addBreakLine(codeStream);
|
||||||
|
|
||||||
if (testExpr->getPreferredType() == TypeReqUInt)
|
TypeReq testType = testExpr->getPreferredType();
|
||||||
|
|
||||||
|
if (testType == TypeReqUInt)
|
||||||
{
|
{
|
||||||
integer = true;
|
integer = true;
|
||||||
}
|
}
|
||||||
|
|
@ -209,8 +211,16 @@ U32 IfStmtNode::compileStmt(CodeStream& codeStream, U32 ip)
|
||||||
integer = false;
|
integer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip = testExpr->compile(codeStream, ip, integer ? TypeReqUInt : TypeReqFloat);
|
if (testType == TypeReqString)
|
||||||
codeStream.emit(integer ? OP_JMPIFNOT : OP_JMPIFFNOT);
|
{
|
||||||
|
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)
|
if (elseBlock)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1144,6 +1144,7 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi
|
||||||
ip++;
|
ip++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip = code[ip];
|
ip = code[ip];
|
||||||
break;
|
break;
|
||||||
case OP_JMPIFF:
|
case OP_JMPIFF:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue