using System; using System.IO; namespace Wasmtime { /// /// Represents the Wasmtime store. /// public sealed class Store : IDisposable { internal Store(Engine engine) { Handle = Interop.wasm_store_new(engine.Handle); if (Handle.IsInvalid) { throw new WasmtimeException("Failed to create Wasmtime store."); } } /// /// Create a given the module name and bytes. /// /// The name of the module. /// The bytes of the module. /// Retuw . public Module CreateModule(string name, byte[] bytes) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } if (bytes is null) { throw new ArgumentNullException(nameof(bytes)); } return new Module(this, name, bytes); } /// /// Create a given the module name and path to the WebAssembly file. /// /// The name of the module. /// The path to the WebAssembly file. /// Returns a new . public Module CreateModule(string name, string path) { return CreateModule(name, File.ReadAllBytes(path)); } /// /// Create a given the path to the WebAssembly file. /// /// The path to the WebAssembly file. /// Returns a new . public Module CreateModule(string path) { return CreateModule(Path.GetFileNameWithoutExtension(path), path); } /// public void Dispose() { if (!Handle.IsInvalid) { Handle.Dispose(); Handle.SetHandleAsInvalid(); } } internal Interop.StoreHandle Handle { get; private set; } } }