// Copyright (c) 2008-2022 the Urho3D project // License: MIT #include "../Precompiled.h" #include "../AngelScript/Script.h" #include "../AngelScript/ScriptFile.h" #include "../AngelScript/ScriptInstance.h" #include "../Core/Context.h" #include "../Core/CoreEvents.h" #include "../Core/Profiler.h" #include "../IO/FileSystem.h" #include "../IO/Log.h" #include "../IO/MemoryBuffer.h" #include "../Resource/ResourceCache.h" #include #include "../DebugNew.h" namespace Urho3D { /// Helper class for saving AngelScript bytecode. class ByteCodeSerializer : public asIBinaryStream { public: /// Construct. explicit ByteCodeSerializer(Serializer& dest) : dest_(dest) { } /// Read from stream (no-op). int Read(void* ptr, asUINT size) override { // No-op, can not read from a Serializer return 0; } /// Write to stream. int Write(const void* ptr, asUINT size) override { return dest_.Write(ptr, size); } private: /// Destination stream. Serializer& dest_; }; /// Helper class for loading AngelScript bytecode. class ByteCodeDeserializer : public asIBinaryStream { public: /// Construct. explicit ByteCodeDeserializer(MemoryBuffer& source) : source_(source) { } /// Read from stream. int Read(void* ptr, asUINT size) override { return source_.Read(ptr, size); } /// Write to stream (no-op). int Write(const void* ptr, asUINT size) override { return 0; } private: /// Source stream. MemoryBuffer& source_; }; ScriptFile::ScriptFile(Context* context) : Resource(context), script_(GetSubsystem