Hello
I want to pass native 'this' to script object
asIScriptObject* CUIScriptable::CreateScriptClass (const char* sClassName)
{
dbg_assert(m_pObjectType == NULL);
dbg_assert(m_pScriptObject == NULL);
dbg_assert(m_pScriptContext == NULL);
int Res;
//context
m_pScriptContext = GetScriptManager()->GetEngine()->CreateContext();
dbg_assert(m_pScriptContext);
//object type
asIScriptModule* pModule = GetScriptManager()->GetEngine()->GetModule(0);
dbg_assert(pModule);
m_pObjectType = GetScriptManager()->GetEngine()->GetObjectTypeById(pModule->GetTypeIdByDecl(sClassName));
dbg_assert(m_pObjectType);
//script object
asIScriptFunction* pFactory = m_pObjectType->GetFactoryByDecl(va("%s @%s()", sClassName, sClassName));
dbg_assert(pFactory);
Res = m_pScriptContext->Prepare(pFactory);
dbg_assert(Res >= 0);
Res = m_pScriptContext->Execute();
dbg_assert(Res >= 0);
m_pScriptObject = *(asIScriptObject**)m_pScriptContext->GetAddressOfReturnValue();
dbg_assert(m_pScriptObject);
// If you're going to store the object you must increase the reference,
// otherwise it will be destroyed when the context is reused or destroyed.
// m_pScriptObject->AddRef();
//call SetThat()
asIScriptFunction* pFunc = m_pObjectType->GetMethodByDecl("void SetThat (CUIScriptable@ That)"); dbg_assert(pFunc);
Res = m_pScriptContext->Prepare(pFunc); dbg_assert(Res >= 0);
Res = m_pScriptContext->SetArgObject(0, this); dbg_assert(Res >= 0);
Res = m_pScriptContext->Execute(); dbg_assert(Res == asEXECUTION_FINISHED);
//
return m_pScriptObject;
}
sClassName is "CHUD_Test"
CHUD_Test.as:
#include 'CUIElement.as'
class CHUD_Test : CUIElement
{
}
CUIElement.as:
class CUIElement : IUIElement
{
void SetThat (CUIScriptable@ That)
{
@that = @That;
}
CUIScriptable@ that;
}
it asserts during last Context::Execute() call, line 1140, comment says "This shouldn't happen" and m_currentFunction->funcType == asFUNC_VIRTUAL
Any ideas?
Thanks in advance