diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 70c72ef5..17e16517 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -368,7 +368,14 @@ void CBotClass::RestoreMethode(long& nIdent, CBotVar** ppParams, CBotStack*& pStack) { - m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, this); + CBotClass* pClass = this; + while (pClass != nullptr) + { + bool ok = pClass->m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, pClass); + if (ok) return; + pClass = pClass->m_parent; + } + assert(false); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 4c15a416..d00e8ea6 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -801,7 +801,7 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis, } //////////////////////////////////////////////////////////////////////////////// -void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars, +bool CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass) { CBotTypResult type; @@ -810,14 +810,20 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* p if ( pt != nullptr ) { CBotStack* pStk = pStack->RestoreStack(pt); - if ( pStk == nullptr ) return; + if ( pStk == nullptr ) return true; pStk->SetProgram(pt->m_pProg); // it may have changed module CBotVar* pthis = pStk->FindVar("this"); pthis->SetUniqNum(-2); + if (pClass->GetParent() != nullptr) + { + CBotVar* psuper = pStk->FindVar("super"); + if (psuper != nullptr) psuper->SetUniqNum(-3); + } + CBotStack* pStk3 = pStk->RestoreStack(nullptr); // to set parameters passed - if ( pStk3 == nullptr ) return; + if ( pStk3 == nullptr ) return true; pt->m_param->RestoreState(pStk3, true); // parameters @@ -831,7 +837,9 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* p // finally calls the found function pt->m_block->RestoreState(pStk3, true); // interrupt ! + return true; } + return false; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h index b0bf501c..76a02bc0 100644 --- a/src/CBot/CBotInstr/CBotFunction.h +++ b/src/CBot/CBotInstr/CBotFunction.h @@ -179,8 +179,9 @@ public: * \param ppVars * \param pStack * \param pClass + * \return Returns true if the method call was restored. */ - void RestoreCall(long& nIdent, + bool RestoreCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars,