SwiftWebAssembly

0.2.0

Load WebAssembly modules from Swift
therealbnut/SwiftWebAssembly

What's New

Improved Documentation

2017-11-26T10:26:39Z

SwiftWebAssembly GitHub license GitHub release Carthage compatible Carthage compatible

SwiftWebAssembly has one purpose, to load WebAssembly compiled modules and exposes them to Swift.

Example

import SwiftWebAssembly
import JavaScriptCore

let context = JSContext()
let file = URL(fileURLWithPath: "example.wasm")
let data = try! Data(contentsOf: file)

context.loadWebAssemblyModule(
    data: data,
    success: { exports in
        let result = exports?["add"]?.call(withArguments: [1, 2])
        print("result: \(result)") // result: 3
    },
    failure: { error in
        print("oh no!")
    })

Integration

Swift Package Manager

The package can be installed through SwiftPM.

  .package(url: "git@github.com:therealbnut/SwiftWebAssembly.git", from: "0.2.0"),

A more complete example:

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyPackage",
    products: [
        .library(name: "MyProduct", targets: ["MyTarget"]),
    ],
    dependencies: [
        .package(url: "git@github.com:therealbnut/SwiftWebAssembly.git", from: "0.2.0"),
    ],
    targets: [
        .target(name: "MyTarget", dependencies: ["SwiftWebAssembly"])
    ]
)

Carthage

Add SwiftWebAssembly to your Cartfile.

Description

  • Swift Tools 4.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Mar 17 2024 16:07:23 GMT-0900 (Hawaii-Aleutian Daylight Time)