2007-06-28 10:47:08 -07:00
|
|
|
/*
|
|
|
|
* Script.c
|
|
|
|
*
|
|
|
|
* A few general functions for the script library
|
|
|
|
*/
|
|
|
|
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/framework/frame.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "script.h"
|
|
|
|
#include <assert.h>
|
2006-06-02 12:34:58 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// Flags for storing function indexes
|
2006-02-28 22:12:28 -08:00
|
|
|
#define FUNC_SETBIT 0x80000000 // set for a set function, clear otherwise
|
2007-06-28 10:47:08 -07:00
|
|
|
#define FUNC_LISTMASK 0x70000000
|
|
|
|
#define FUNC_INDEXMASK 0x0fffffff
|
|
|
|
#define FUNC_INSTINCT 0x00000000 // instinct function
|
|
|
|
#define FUNC_CALLBACK 0x40000000 // callback function
|
2006-02-28 22:12:28 -08:00
|
|
|
#define FUNC_OBJVAR 0x10000000 // object variable
|
2007-06-28 10:47:08 -07:00
|
|
|
#define FUNC_EXTERNAL 0x20000000 // external variable
|
|
|
|
|
|
|
|
|
|
|
|
// Initialise the script library
|
|
|
|
BOOL scriptInitialise(EVENT_INIT *psInit)
|
|
|
|
{
|
|
|
|
if (!stackInitialise())
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!interpInitialise())
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!eventInitialise(psInit))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown the script library
|
|
|
|
void scriptShutDown(void)
|
|
|
|
{
|
|
|
|
eventShutDown();
|
|
|
|
stackShutDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Free a SCRIPT_CODE structure */
|
|
|
|
void scriptFreeCode(SCRIPT_CODE *psCode)
|
|
|
|
{
|
2006-08-20 07:48:14 -07:00
|
|
|
UDWORD i,j;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-09-19 09:07:06 -07:00
|
|
|
debug(LOG_WZ, "Unloading script data");
|
|
|
|
|
|
|
|
|
|
|
|
/* Free local vars */
|
|
|
|
for(i=0; i < psCode->numEvents; i++)
|
|
|
|
{
|
|
|
|
if(psCode->numLocalVars[i] > 0) //only free if any defined
|
|
|
|
{
|
|
|
|
//free strings for event i
|
|
|
|
for(j=0; j < psCode->numLocalVars[i]; j++)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(psCode->ppsLocalVarVal[i][j].type == VAL_STRING) //if a string
|
|
|
|
{
|
|
|
|
if(psCode->ppsLocalVarVal[i][j].v.sval != NULL) //doublecheck..
|
|
|
|
{
|
|
|
|
FREE(psCode->ppsLocalVarVal[i][j].v.sval); //free string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE(psCode->ppsLocalVars[i]);
|
|
|
|
FREE(psCode->ppsLocalVarVal[i]); //free pointer to event i local vars
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
FREE(psCode->pCode);
|
|
|
|
if (psCode->pTriggerTab)
|
|
|
|
{
|
|
|
|
FREE(psCode->pTriggerTab);
|
|
|
|
}
|
|
|
|
if (psCode->psTriggerData)
|
|
|
|
{
|
|
|
|
FREE(psCode->psTriggerData);
|
|
|
|
}
|
|
|
|
FREE(psCode->pEventTab);
|
|
|
|
FREE(psCode->pEventLinks);
|
|
|
|
if (psCode->pGlobals != NULL)
|
|
|
|
{
|
|
|
|
FREE(psCode->pGlobals);
|
|
|
|
}
|
|
|
|
if (psCode->psArrayInfo != NULL)
|
|
|
|
{
|
|
|
|
FREE(psCode->psArrayInfo);
|
|
|
|
}
|
|
|
|
if (psCode->psDebug)
|
|
|
|
{
|
|
|
|
for(i=0; i<psCode->debugEntries; i++)
|
|
|
|
{
|
|
|
|
if (psCode->psDebug[i].pLabel)
|
|
|
|
{
|
|
|
|
FREE(psCode->psDebug[i].pLabel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FREE(psCode->psDebug);
|
|
|
|
}
|
|
|
|
if (psCode->psVarDebug)
|
|
|
|
{
|
|
|
|
for(i=0; i<psCode->numGlobals; i++)
|
|
|
|
{
|
|
|
|
if (psCode->psVarDebug[i].pIdent)
|
|
|
|
{
|
|
|
|
FREE(psCode->psVarDebug[i].pIdent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FREE(psCode->psVarDebug);
|
|
|
|
}
|
|
|
|
if (psCode->psArrayDebug)
|
|
|
|
{
|
|
|
|
for(i=0; i<psCode->numArrays; i++)
|
|
|
|
{
|
|
|
|
if (psCode->psArrayDebug[i].pIdent)
|
|
|
|
{
|
|
|
|
FREE(psCode->psArrayDebug[i].pIdent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FREE(psCode->psArrayDebug);
|
|
|
|
}
|
2006-08-15 11:38:51 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-26 11:14:05 -07:00
|
|
|
if(psCode->numParams != NULL)
|
|
|
|
FREE(psCode->numParams);
|
2006-08-20 07:48:14 -07:00
|
|
|
|
2006-09-26 11:14:05 -07:00
|
|
|
if(psCode->numLocalVars != NULL)
|
|
|
|
FREE(psCode->numLocalVars);
|
|
|
|
|
|
|
|
if(psCode->ppsLocalVars != NULL)
|
|
|
|
FREE(psCode->ppsLocalVars);
|
|
|
|
|
|
|
|
if(psCode->ppsLocalVarVal != NULL)
|
|
|
|
FREE(psCode->ppsLocalVarVal);
|
2006-08-15 11:38:51 -07:00
|
|
|
|
2006-08-20 07:48:14 -07:00
|
|
|
psCode->numEvents = 0;
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
FREE(psCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Lookup a script variable */
|
|
|
|
BOOL scriptGetVarIndex(SCRIPT_CODE *psCode, STRING *pID, UDWORD *pIndex)
|
|
|
|
{
|
|
|
|
UDWORD index;
|
|
|
|
|
|
|
|
if (!psCode->psVarDebug)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(index=0; index<psCode->numGlobals; index++)
|
|
|
|
{
|
|
|
|
if (strcmp(psCode->psVarDebug[index].pIdent, pID)==0)
|
|
|
|
{
|
|
|
|
*pIndex = index;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|