This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void print_str(wasmer_instance_context_t *ctx, int32_t ptr, int32_t len) | |
{ | |
print_str_called = true; | |
wasmer_memory_t *memory = wasmer_instance_context_memory(ctx, 0); | |
uint32_t mem_len = wasmer_memory_length(memory); | |
uint8_t *mem_bytes = wasmer_memory_data(memory); | |
printf("%.*s", len, mem_bytes + ptr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "wasmer.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern void print_str(char *ptr, int len); | |
int hello_wasm() | |
{ | |
char *str = "Hello, World!"; | |
print_str(str, 13); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "rust-build/src/wasmer-runtime-c-api/lib/runtime-c-api/wasmer.h" | |
#include <assert.h> | |
#include <stdint.h> | |
static print_str_called = false; | |
// Host function that will be imported into the Web Assembly Instance | |
void print_str(wasmer_instance_context_t *ctx, int32_t ptr, int32_t len) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define a function that is imported into the module. | |
// By default, the "env" namespace is used. | |
extern "C" { | |
fn print_str(ptr: *const u8, len: usize); | |
} | |
// Define a string that is accessible within the wasm | |
// linear memory. | |
static HELLO: &'static str = "Hello, World!"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate wasmer_runtime; | |
use std::{fs::File, io::prelude::*, str}; | |
use wasmer_runtime::{self as runtime, prelude::*}; | |
fn main() { | |
// Read the wasm file produced by our sample application... | |
let mut wasm_file = | |
File::open("./wasm-sample-app/target/wasm32-unknown-unknown/release/wasm_sample_app.wasm") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Defines functions to import from "env" namespace | |
extern "C" { | |
fn print_str(ptr: *const u8, len: usize); | |
} | |
#[no_mangle] | |
pub extern fn hello_wasm(){ | |
let message = "Hello World"; | |
unsafe { | |
print_str(message.as_ptr(), message.len()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html><head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/two.js/0.6.0/two.js"></script> | |
</head> | |
<body> | |
<div id="main"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Conway's Game of Life - AssemblyScript</title> | |
<link rel="icon" href="http://assemblyscript.org/favicon.ico" type="image/x-icon" /> | |
<meta name="viewport" content="user-scalable=0" /> | |
<style> | |
/* html, body { height: 100%; margin: 0; overflow: hidden; color: #111; background: #fff; font-family: sans-serif; } */ | |
/* body { border-top: 2px solid #bc18d4; } | |
h1 { padding: 18px 20px 20px; font-size: 12pt; margin: 0; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. | |
# This code is released under a tri EPL/GPL/LGPL license. You can use it, | |
# redistribute it and/or modify it under the terms of the: | |
# | |
# Eclipse Public License version 1.0 | |
# GNU General Public License version 2 | |
# GNU Lesser General Public License version 2.1 | |
# Run with ruby tool/update-mri-cext.rb |