5.3.1. PreprocessorLoad

[<<<] [>>>]

This entry point is used when the preprocessor is loaded. The pointer p is NULL.

When the preprocessor function is called with this argument it can be sure that this is the very first call to the function within the actual interpreter thread. It also can depend on the support function table and on the preprocessor memory segment pointer being initialized and ready to allocate memory.

It has to check that the version the preprocessor was designed and compiled for is appropriate and works together with the ScriptBasic interpreter that invoked the preprocessor. This can easily be done checking the version information in the preprocessor structure. Sample code:

      if( pEXT->lVersion != IP_INTERFACE_VERSION ){
        *pCmd = PreprocessorUnload;
        return 0;
        }

This code is the appropriate place to allocate space for the preprocessor structure that hold the thread local variables. For example:

      pDO = pEXT->pST->Alloc(sizeof(DebuggerObject),pEXT->pMemorySegment);
      *pCmd = PreprocessorUnload;
      if( pDO == NULL )return 1;

Note that this example is a simplified version of the one that you can find in the sample debugger preprocessor. This example uses the Alloc support function that is usually points to the function alloc_Alloc implemented in the file `myalloc.c'. When coding an external preprocessor you can rely on ScriptBasic that as soon as the preprocessor is unloaded the memory allocated using this function with the memory segment initiated for the preprocessor (like above) will be released.

The preprocessor has to return the error code or zero and may alter the value of the parameter *pCmd to PreprocessorContinue or PreprocessorUnload.

Although the calling code ignores the value returned in *pCmd unless it is PreprocessorUnload it is required by principle to set a value in this variable. The value PreprocessorDone can not be used when returning from this entry.


[<<<] [>>>]