Example #1
0
    def test_hello_world(self):
        instance = Instance(TEST_BYTES)
        pointer = instance.call('string')
        memory = instance.uint8_memory_view(pointer)
        nth = 0
        string = ''

        while (0 != memory[nth]):
            string += chr(memory[nth])
            nth += 1

        self.assertEqual(string, 'Hello, World!')
Example #2
0
from wasmer import Instance, Value
import os

__dir__ = os.path.dirname(os.path.realpath(__file__))

wasm_bytes = open(__dir__ + '/simple.wasm', 'rb').read()
instance = Instance(wasm_bytes)
result = instance.call('sum', [Value.i32(5), Value.i32(37)])

print(result) # 42!
Example #3
0
from wasmer import Instance, Value
import os

__dir__ = os.path.dirname(os.path.realpath(__file__))

wasm_bytes = open(__dir__ + '/memory.wasm', 'rb').read()
instance = Instance(wasm_bytes)
pointer = instance.call('return_hello')

memory = instance.uint8_memory_view(pointer)
nth = 0;
string = '';

while (0 != memory[nth]):
    string += chr(memory[nth])
    nth += 1

print('"' + string + '"') # "Hello, World!"