Coder Social home page Coder Social logo

liigo / wasm-bindgen Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rustwasm/wasm-bindgen

0.0 2.0 0.0 2.76 MB

Facilitating high-level interactions between wasm modules and JavaScript

Home Page: https://rustwasm.github.io/wasm-bindgen/

License: Apache License 2.0

JavaScript 0.16% Rust 42.31% IDL 55.01% Shell 0.02% WebIDL 1.92% C++ 0.59%

wasm-bindgen's Introduction

wasm-bindgen

Facilitating high-level interactions between wasm modules and JavaScript.

Introduction blog post: "JavaScript to Rust and Back Again: A wasm-bindgen Tale"

Build Status Build status API Documentation on docs.rs

Import JavaScript things into Rust and export Rust things to JavaScript.

src/lib.rs:

#![feature(proc_macro, wasm_custom_section, wasm_import_module)]

extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;

// Import the `window.alert` function from the Web.
#[wasm_bindgen]
extern {
    fn alert(s: &str);
}

// Export a `greet` function from Rust to JavaScript, that alerts a
// hello message.
#[wasm_bindgen]
pub fn greet(name: &str) {
    alert(&format!("Hello, {}!", name));
}

Use exported Rust things from JavaScript!

index.js:

// Asynchronously load, compile, and import the Rust's WebAssembly
// and JavaScript interface.
import("./hello_world").then(module => {
  // Alert "Hello, World!"
  module.greet("World!");
});

Guide

๐Ÿ“š Read the wasm-bindgen guide here! ๐Ÿ“š

License

This project is licensed under either of

at your option.

Contribution

See the "Contributing" section of the guide for information on hacking on wasm-bindgen!

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

wasm-bindgen's People

Contributors

alexcrichton avatar fitzgen avatar sendilkumarn avatar jannikkeye avatar ohanar avatar jonathan-s avatar belfz avatar wismer avatar rylev avatar hywan avatar pepsighan avatar toversus avatar xeqlol avatar akryvomaz avatar konstin avatar dependabot[bot] avatar dependabot-support avatar elpiel avatar ashleygwilliams avatar brisad avatar dflemstr avatar spastorino avatar srenatus avatar xtuc avatar jhenninger avatar frankhassanabad avatar limira avatar kzvi avatar zerothlaw avatar freemasen avatar

Watchers

Liigo Zhuang avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.