Esempio n. 1
0
/* Display a value  */
void cpPrintVal(INTERP_VAL value)
{
	if (value.type & VAL_REF)
	{
		value.type = (INTERP_TYPE)(value.type & ~VAL_REF);
		debug( LOG_NEVER, "type: %5s, value: %i (ref)",
			scriptTypeToString(value.type), value.v.ival );
		return;
	}

	switch(value.type)
	{
		case VAL_BOOL:
			debug( LOG_NEVER, "type: %5s, value: %s",
				scriptTypeToString(value.type),
				bool2string(value.v.bval) );
			break;
		case VAL_INT:
			debug( LOG_NEVER, "type: %5s, value: %d",
				scriptTypeToString(value.type),
				value.v.ival );
			break;
		case VAL_FLOAT:
			debug( LOG_NEVER, "type: %5s, value: %f",
				scriptTypeToString(value.type),
				value.v.fval );
			break;
		case VAL_STRING:
			debug( LOG_NEVER, "type: %5s, value: %s",
				scriptTypeToString(value.type),
				value.v.sval );
			break;
		case VAL_TRIGGER:
		case VAL_EVENT:
		default:
			debug( LOG_NEVER, "type: %5s, value: %d",
				scriptTypeToString(value.type),
				value.v.ival );
			break;
	}
}
Esempio n. 2
0
// save the context information for the script system
static bool eventSaveContext(WzConfig &ini)
{
    int numVars, numContext = 0;
    UDWORD hashedName;

    // go through the context list
    for (SCRIPT_CONTEXT *psCCont = psContList; psCCont != NULL; psCCont = psCCont->psNext)
    {
        // save the context info
        if (!resGetHashfromData("SCRIPT", psCCont->psCode, &hashedName))
        {
            debug(LOG_FATAL, "Could not find script resource id");
            return false;
        }
        numVars = psCCont->psCode->numGlobals + psCCont->psCode->arraySize;

        ini.beginGroup("context_" + QString::number(numContext));
        ini.setValue("context", hashedName);
        ini.setValue("numVars", numVars);
        ini.setValue("release", psCCont->release);
        ini.beginGroup("var");

        // save the context variables
        int countVar = 0;
        for (VAL_CHUNK *psCVals = psCCont->psGlobals; psCVals != NULL; psCVals = psCVals->psNext)
        {
            for (int i = 0; i < CONTEXT_VALS; i++)
            {
                INTERP_VAL *psVal = psCVals->asVals + i;

                ASSERT(psVal->type < SWORD_MAX, "Variable type number %d too big", (int)psVal->type);

                ini.beginGroup(QString::number(countVar));
                ini.setValue("type", QVariant(psVal->type));
                ini.setValue("typename", QString(scriptTypeToString(psVal->type))); // for debugging

                // store the variable value
                if (psVal->type == VAL_STRING)
                {
                    ini.setValue("data", QString(psVal->v.sval));
                }
                else if (psVal->type == VAL_BOOL)
                {
                    ini.setValue("data", QVariant((bool)psVal->v.bval));
                }
                else if (psVal->type == VAL_FLOAT)
                {
                    ini.setValue("data", QVariant((float)psVal->v.fval));
                }
                else if (psVal->type == VAL_OBJ_GETSET || psVal->type == VAL_FUNC_EXTERN)
                {
                    ini.setValue("data", QString("n/a"));
                }
                else if (psVal->type < VAL_USERTYPESTART)
                {
                    ini.setValue("data", QVariant(psVal->v.ival));
                }
                else
                {
                    // user defined type
                    SCR_VAL_SAVE saveFunc = asScrTypeTab[psVal->type - VAL_USERTYPESTART].saveFunc;

                    ASSERT(saveFunc != NULL, "No save function for type %d", psVal->type);

                    if (!saveFunc(psVal, ini))
                    {
                        debug(LOG_FATAL, "Could not get user defined variable value");
                        return false;
                    }
                }

                numVars -=1;
                countVar++;
                ini.endGroup();
                if (numVars <= 0)
                {
                    // done all the variables
                    ASSERT(psCVals->psNext == NULL, "Number of context variables does not match the script code");
                    break;
                }
            }
        }
        ASSERT(numVars == 0, "Number of context variables does not match the script code (%d)", numVars);
        ini.endGroup();
        ini.endGroup();
        numContext++;
    }

    // actually store how many contexts have been saved
    ini.setValue("general/contexts", QVariant(numContext));

    return true;
}