[colobot] 106/145: Fix conversion to string with = operator
Didier Raboud
odyx at moszumanska.debian.org
Mon Jul 11 12:56:22 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit 37ab015c8db1c29cbd01e849fd6cc586b60c794d
Author: melex750 <melex750 at users.noreply.github.com>
Date: Sun May 29 06:55:28 2016 -0400
Fix conversion to string with = operator
---
src/CBot/CBotInstr/CBotExpression.cpp | 23 +++++++++++++++++++++--
src/CBot/CBotInstr/CBotLeftExprVar.cpp | 6 ++++++
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp
index cb7f3df..c98deca 100644
--- a/src/CBot/CBotInstr/CBotExpression.cpp
+++ b/src/CBot/CBotInstr/CBotExpression.cpp
@@ -71,6 +71,13 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
return nullptr;
}
+ if ( p->GetType() == ID_SEP )
+ {
+ pStack->SetError(CBotErrNoExpression, p);
+ delete inst;
+ return nullptr;
+ }
+
inst->m_rightop = CBotExpression::Compile(p, pStack);
if (inst->m_rightop == nullptr)
{
@@ -118,13 +125,13 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
break;
case ID_ASSADD:
if (type2.Eq(CBotTypBoolean) ||
- type2.Eq(CBotTypPointer) ) type2 = -1; // numbers and strings
+ type2.GetType() > CBotTypString ) type2.SetType(-1); // numbers and strings
break;
case ID_ASSSUB:
case ID_ASSMUL:
case ID_ASSDIV:
case ID_ASSMODULO:
- if (type2.GetType() >= CBotTypBoolean) type2 = -1; // numbers only
+ if (type2.GetType() >= CBotTypBoolean) type2.SetType(-1); // numbers only
break;
}
@@ -179,6 +186,18 @@ bool CBotExpression::Execute(CBotStack* &pj)
if ( pile2->GetState()==0)
{
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();
}
diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp
index 848d16a..4394fc4 100644
--- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp
+++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp
@@ -64,6 +64,12 @@ bool CBotLeftExprVar::Execute(CBotStack* &pj)
CBotVar* var2 = pj->GetVar(); // Initial value on the stack
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
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list