Skip to content

Commit

Permalink
Bring Function examples from old HostFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Oct 8, 2024
1 parent edf000f commit 0545d10
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 27 additions & 0 deletions Sources/WasmKit/Execution/Function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ import struct WasmTypes.FunctionType
///
/// > Note:
/// <https://webassembly.github.io/spec/core/exec/runtime.html#function-instances>
///
/// ## Examples
///
/// This example section shows how to interact with WebAssembly process with ``Function``.
///
/// ### Print Int32 given by WebAssembly process
///
/// ```swift
/// Function(store: store, parameters: [.i32]) { _, args in
/// print(args[0])
/// return []
/// }
/// ```
///
/// ### Print a UTF-8 string passed by a WebAssembly module instance
///
/// ```swift
/// Function(store: store, parameters: [.i32, .i32]) { caller, args in
/// let (stringPtr, stringLength) = (Int(args[0].i32), Int(args[1].i32))
/// guard let memory = caller.instance?.exports[memory: "memory"] else {
/// fatalError("Missing \"memory\" export")
/// }
/// let bytesRange = stringPtr..<(stringPtr + stringLength)
/// print(String(decoding: memory.data[bytesRange], as: UTF8.self))
/// return []
/// }
/// ```
public struct Function: Equatable {
internal let handle: InternalFunction
let store: Store
Expand Down
2 changes: 0 additions & 2 deletions Sources/WasmKit/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ typealias LabelIndex = UInt32

// MARK: - Module Entities

/// TODO: Rename to `GuestFunctionEntity`
///
/// An executable function representation in a module
/// > Note:
/// <https://webassembly.github.io/spec/core/syntax/modules.html#functions>
Expand Down

0 comments on commit 0545d10

Please sign in to comment.