void asCRestore::ReadFunction(asCScriptFunction* func) { int i, count; asCDataType dt; int num; ReadString(&func->name); ReadDataType(&func->returnType); READ_NUM(count); func->parameterTypes.Allocate(count, 0); for( i = 0; i < count; ++i ) { ReadDataType(&dt); func->parameterTypes.PushLast(dt); } READ_NUM(func->id); READ_NUM(count); func->byteCode.Allocate(count, 0); ReadByteCode(func->byteCode.AddressOf(), count); func->byteCode.SetLength(count); READ_NUM(count); func->objVariablePos.Allocate(count, 0); func->objVariableTypes.Allocate(count, 0); for( i = 0; i < count; ++i ) { func->objVariableTypes.PushLast(ReadObjectType()); READ_NUM(num); func->objVariablePos.PushLast(num); } READ_NUM(func->stackNeeded); func->objectType = ReadObjectType(); int length; READ_NUM(length); func->lineNumbers.SetLength(length); for( i = 0; i < length; ++i ) READ_NUM(func->lineNumbers[i]); }
asCScriptFunction *asCRestore::ReadFunction(bool addToModule, bool addToEngine) { char c; READ_NUM(c); if( c == '\0' ) { // There is no function, so return a null pointer return 0; } if( c == 'r' ) { // This is a reference to a previously saved function int index; READ_NUM(index); return savedFunctions[index]; } // Load the new function asCScriptFunction *func = asNEW(asCScriptFunction)(engine,module,-1); savedFunctions.PushLast(func); int i, count; asCDataType dt; int num; ReadFunctionSignature(func); if( func->funcType == asFUNC_SCRIPT ) engine->gc.AddScriptObjectToGC(func, &engine->functionBehaviours); func->id = engine->GetNextScriptFunctionId(); READ_NUM(count); func->byteCode.Allocate(count, 0); ReadByteCode(func->byteCode.AddressOf(), count); func->byteCode.SetLength(count); READ_NUM(count); func->objVariablePos.Allocate(count, 0); func->objVariableTypes.Allocate(count, 0); for( i = 0; i < count; ++i ) { func->objVariableTypes.PushLast(ReadObjectType()); READ_NUM(num); func->objVariablePos.PushLast(num); } READ_NUM(func->stackNeeded); int length; READ_NUM(length); func->lineNumbers.SetLength(length); for( i = 0; i < length; ++i ) READ_NUM(func->lineNumbers[i]); READ_NUM(func->vfTableIdx); if( addToModule ) { // The refCount is already 1 module->scriptFunctions.PushLast(func); } if( addToEngine ) engine->SetScriptFunction(func); if( func->objectType ) func->ComputeSignatureId(); ReadGlobalVarPointers(func); return func; }