using System; using System.Collections.Generic; using Wasmtime.Exports; namespace Wasmtime.Externs { /// /// Represents external (instantiated) WebAssembly functions, globals, tables, and memories. /// public class Externs { internal Externs(Wasmtime.Exports.Exports exports, Interop.wasm_extern_vec_t externs) { var functions = new List(); var globals = new List(); var memories = new List(); for (int i = 0; i < (int)externs.size; ++i) { unsafe { var ext = externs.data[i]; switch (Interop.wasm_extern_kind(ext)) { case Interop.wasm_externkind_t.WASM_EXTERN_FUNC: var function = new ExternFunction((FunctionExport)exports.All[i], Interop.wasm_extern_as_func(ext)); functions.Add(function); break; case Interop.wasm_externkind_t.WASM_EXTERN_GLOBAL: var global = new ExternGlobal((GlobalExport)exports.All[i], Interop.wasm_extern_as_global(ext)); globals.Add(global); break; case Interop.wasm_externkind_t.WASM_EXTERN_MEMORY: var memory = new ExternMemory((MemoryExport)exports.All[i], Interop.wasm_extern_as_memory(ext)); memories.Add(memory); break; default: throw new NotSupportedException("Unsupported extern type."); } } } Functions = functions; Globals = globals; Memories = memories; } /// /// The extern functions from an instantiated WebAssembly module. /// public IReadOnlyList Functions { get; private set; } /// /// The extern globals from an instantiated WebAssembly module. /// public IReadOnlyList Globals { get; private set; } /// /// The extern memories from an instantiated WebAssembly module. /// public IReadOnlyList Memories { get; private set; } } }