Fixed object:: with other types (#207)

dev-time-step
krzys-h 2015-12-25 15:13:52 +01:00
parent 5b7638d9f4
commit 0807b75d4b
2 changed files with 18 additions and 3 deletions

View File

@ -178,6 +178,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
if ( IsOfType( p, ID_DBLDOTS ) ) // method for a class
{
func->m_MasterClass = pp->GetString();
func->m_classToken = *pp;
CBotClass* pClass = CBotClass::Find(pp);
if ( pClass == nullptr ) goto bad;
@ -355,10 +356,16 @@ bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
}
else
{
if (m_MasterClass != pInstance->GetClass()->GetName())
{
pile->SetError(CBotErrBadType2, &m_classToken);
return false;
}
pThis = CBotVar::Create("this", CBotTypResult( CBotTypPointer, m_MasterClass ));
pThis->SetPointer(pInstance);
}
assert(pThis);
assert(pThis != nullptr);
pThis->SetInit(CBotVar::InitType::IS_POINTER);
// pThis->SetUniqNum(m_nThisIdent);
@ -617,10 +624,16 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars
}
else
{
if (pt->m_MasterClass != pInstance->GetClass()->GetName())
{
pStack->SetError(CBotErrBadType2, &pt->m_classToken);
return false;
}
pThis = CBotVar::Create("this", CBotTypResult( CBotTypPointer, pt->m_MasterClass ));
pThis->SetPointer(pInstance);
}
assert(pThis);
assert(pThis != nullptr);
pThis->SetInit(CBotVar::InitType::IS_POINTER);
pThis->SetUniqNum(-2);

View File

@ -261,8 +261,10 @@ private:
bool m_bPublic;
//! Extern function.
bool m_bExtern;
//! Name of the class we derive.
//! Name of the class we are part of
std::string m_MasterClass;
//! Token of the class we are part of
CBotToken m_classToken;
CBotProgram* m_pProg;
//! For the position of the word "extern".
CBotToken m_extern;