Fix conversion to string with = operator

master
melex750 2016-05-29 06:55:28 -04:00
parent 6db2832577
commit 37ab015c8d
2 changed files with 27 additions and 2 deletions

View File

@ -71,6 +71,13 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
return nullptr; return nullptr;
} }
if ( p->GetType() == ID_SEP )
{
pStack->SetError(CBotErrNoExpression, p);
delete inst;
return nullptr;
}
inst->m_rightop = CBotExpression::Compile(p, pStack); inst->m_rightop = CBotExpression::Compile(p, pStack);
if (inst->m_rightop == nullptr) if (inst->m_rightop == nullptr)
{ {
@ -118,13 +125,13 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
break; break;
case ID_ASSADD: case ID_ASSADD:
if (type2.Eq(CBotTypBoolean) || if (type2.Eq(CBotTypBoolean) ||
type2.Eq(CBotTypPointer) ) type2 = -1; // numbers and strings type2.GetType() > CBotTypString ) type2.SetType(-1); // numbers and strings
break; break;
case ID_ASSSUB: case ID_ASSSUB:
case ID_ASSMUL: case ID_ASSMUL:
case ID_ASSDIV: case ID_ASSDIV:
case ID_ASSMODULO: case ID_ASSMODULO:
if (type2.GetType() >= CBotTypBoolean) type2 = -1; // numbers only if (type2.GetType() >= CBotTypBoolean) type2.SetType(-1); // numbers only
break; break;
} }
@ -179,6 +186,18 @@ bool CBotExpression::Execute(CBotStack* &pj)
if ( pile2->GetState()==0) if ( pile2->GetState()==0)
{ {
if (m_rightop && !m_rightop->Execute(pile2)) return false; // initial value // interrupted? if (m_rightop && !m_rightop->Execute(pile2)) return false; // initial value // interrupted?
if (m_rightop)
{
CBotVar* var = pile1->GetVar();
CBotVar* value = pile2->GetVar();
if (var->GetType() == CBotTypString && value->GetType() != CBotTypString)
{
CBotVar* newVal = CBotVar::Create("", var->GetTypResult());
value->Update(pj->GetUserPtr());
newVal->SetValString(value->GetValString());
pile2->SetVar(newVal);
}
}
pile2->IncState(); pile2->IncState();
} }

View File

@ -64,6 +64,12 @@ bool CBotLeftExprVar::Execute(CBotStack* &pj)
CBotVar* var2 = pj->GetVar(); // Initial value on the stack CBotVar* var2 = pj->GetVar(); // Initial value on the stack
if (var2 != nullptr) if (var2 != nullptr)
{ {
if (m_typevar.Eq(CBotTypString) && var2->GetType() != CBotTypString)
{
var2->Update(pj->GetUserPtr());
var1->SetValString(var2->GetValString());
return true;
}
var1->SetVal(var2); // Set the value var1->SetVal(var2); // Set the value
} }