sidepelican / WasmCallableKit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WasmCallableKit

Use Swift library in TypeScript through WebAssembly!

Example

A Swift class

public enum FenceOrientation: String, Codable {
    case horizontal
    case vertical
}

public struct FencePoint: Codable {
    public var x: Int
    public var y: Int
    public var orientation: FenceOrientation
}

public struct Board: Codable {
    ...
    public var fences: [FencePoint]
}

public class QuoridorGame {
    private var state: ...
    public init() {}

    public func putFence(position: FencePoint) throws { ... }
    public func currentBoard() -> Board { ... }
}

Can be used in TypeScript using WasmCallableKit.

const game = new QuoridorGame();
game.putFence({
    x: 1, y: 4, orientation: "horizontal"
});
const board = game.currentBoard();
board.fences.map(...);

Setup

It is recommended to undestand SwiftWasm book deeply. https://book.swiftwasm.org

🚧 WIP 🚧

You can see example project to understand basic usage.

About

License:MIT License


Languages

Language:Swift 73.2%Language:TypeScript 23.9%Language:C 3.0%