engine/source/scriptlib/Interpreter.c
/******************************************************************************
*  Call -- This method calls the method designated by variable, assuming it
*          exists in the script somewhere.  If there is a return value, it is
*          placed into the pRetValue ScriptVariant.
*  Parameters: method -- a LPCSTR which denotes the method to call
*              pRetValue -- a pointer to a ScriptVariant which accepts the
*                           return value, if any.
*  Returns: S_OK
*           E_FAIL
******************************************************************************/
- This method calls the method designated by variable, assuming it
exists in the script somewhere.  If there is a return value, it is
placed into the pRetValue ScriptVariant.
Parameters: method -- a LPCSTR which denotes the method to call
pRetValue -- a pointer to a ScriptVariant which accepts the
return value, if any.
- This method calls the method designated by variable assuming it exists in the script somewhere . If there is a return value it is placed into the pRetValue ScriptVariant . Parameters : method -- a LPCSTR which denotes the method to call pRetValue -- a pointer to a ScriptVariant which accepts the return value if any .
HRESULT Interpreter_Call(Interpreter *pinterpreter)
{
    HRESULT hr = E_FAIL;
    Instruction **temp = pinterpreter->pCurrentCall;
    Instruction **pCurrentCall = (Instruction **)(pinterpreter->pCurrentInstruction);
    Instruction *currentCall;
    ScriptVariant *pretvar;
    static char buf[256];
    int i;
    if(pCurrentCall == NULL)
    {
        hr = E_FAIL;
        goto endcall;
    }
    pinterpreter->pCurrentCall = pCurrentCall;
    currentCall = *((Instruction **)(pinterpreter->pCurrentInstruction));
    if (currentCall->ptheJumpTarget)
    {
        pinterpreter->pCurrentInstruction = currentCall->ptheJumpTarget;
        hr = Interpreter_EvaluateCall(pinterpreter);
    }
    else if( currentCall->functionRef)
    {
        pretvar = currentCall->theVal;
        hr = currentCall->functionRef((ScriptVariant **)currentCall->theRefList->solidlist, &(pretvar), (int)currentCall->theRef->lVal);
        if(FAILED(hr))
        {
            List_Includes(pinterpreter->ptheFunctionList, currentCall->functionRef);
            printf("Script function '%s' returned an exception, check the manual for details.\n", List_GetName(pinterpreter->ptheFunctionList));
            if(currentCall->theRef->lVal)
            {
                printf(" parameters: ");
                for(i = 0; i < (int)currentCall->theRef->lVal; i++)
                {
                    ScriptVariant_ToString(((ScriptVariant **)currentCall->theRefList->solidlist)[i], buf);
                    if(((ScriptVariant **)currentCall->theRefList->solidlist)[i]->vt == VT_STR)
                    {
                        printf("\"%s\", ", buf);
                    }
                    else
                    {
                        printf("%s, ", buf);
                    }
                }
                printf(" \n ");
            }
        }
    }
    else
    {
        hr = E_FAIL;
        goto endcall;
    }
    if (SUCCEEDED(hr))
    {
        pinterpreter->pCurrentInstruction = pCurrentCall;
    }
    pinterpreter->pCurrentCall = temp;
endcall:
    pinterpreter->bCallCompleted = !pinterpreter->bReset;
    return hr;
}
HRESULT Interpreter_Call ( Interpreter * pinterpreter ) { HRESULT hr = E_FAIL ; Instruction * * temp = pinterpreter -> pCurrentCall ; Instruction * * pCurrentCall = ( Instruction * * ) ( pinterpreter -> pCurrentInstruction ) ; Instruction * currentCall ; ScriptVariant * pretvar ; static char buf [ 256 ] ; int i ; if ( pCurrentCall == NULL ) { hr = E_FAIL ; goto endcall ; } pinterpreter -> pCurrentCall = pCurrentCall ; currentCall = * ( ( Instruction * * ) ( pinterpreter -> pCurrentInstruction ) ) ; if ( currentCall -> ptheJumpTarget ) { pinterpreter -> pCurrentInstruction = currentCall -> ptheJumpTarget ; hr = Interpreter_EvaluateCall ( pinterpreter ) ; } else if ( currentCall -> functionRef ) { pretvar = currentCall -> theVal ; hr = currentCall -> functionRef ( ( ScriptVariant * * ) currentCall -> theRefList -> solidlist , & ( pretvar ) , ( int ) currentCall -> theRef -> lVal ) ; if ( FAILED ( hr ) ) { List_Includes ( pinterpreter -> ptheFunctionList , currentCall -> functionRef ) ; printf ( " \n " , List_GetName ( pinterpreter -> ptheFunctionList ) ) ; if ( currentCall -> theRef -> lVal ) { printf ( " " ) ; for ( i = 0 ; i < ( int ) currentCall -> theRef -> lVal ; i ++ ) { ScriptVariant_ToString ( ( ( ScriptVariant * * ) currentCall -> theRefList -> solidlist ) [ i ] , buf ) ; if ( ( ( ScriptVariant * * ) currentCall -> theRefList -> solidlist ) [ i ] -> vt == VT_STR ) { printf ( " \" \" " , buf ) ; } else { printf ( " " , buf ) ; } } printf ( " \n " ) ; } } } else { hr = E_FAIL ; goto endcall ; } if ( SUCCEEDED ( hr ) ) { pinterpreter -> pCurrentInstruction = pCurrentCall ; } pinterpreter -> pCurrentCall = temp ; endcall : pinterpreter -> bCallCompleted = ! pinterpreter -> bReset ; return hr ; }
Call -- This method calls the method designated by variable, assuming it
exists in the script somewhere.
Call -- This method calls the method designated by variable assuming it exists in the script somewhere .
//Search for the specified entry point. // ScriptVariant_Clear(pretvar); // commenting this out since ScriptVariant_ChangeType is now doing the job //jump back //Reset the m_bCallCompleted flag back to false