This example package demonstrates compiling a C program, types.c
which working with types pased to WASM from JS
emcc is required to compile the add.c
code to a WASM binary:
npm run build
A types.wasm
file will be produced in the build
directory
Test the module outside of the context of the blockchain:
npm test
This will run NodeJS based tests in the test
directory. For example in types.unit.spec.js
test instantiation of the compiled WASM module, and assertions to verify its API and behavior:
describe('Integers', function () {
it('Mult Ints', async function () {
assert.strictEqual(wasm.instance.exports._mult(3, 99), 297); //Assert that the product of 3 and 99 is 297, checking strictly that the type return is equal to number
});
...
});
Return the number 10
Add two integers, return the result
Multiply two integers, return the result
Return the double representation of 10.01
Returns the float result of adding two floating point numbers together
Return the integer representation of true (1)
Return the integer representation of false (0)
Return the integer representation of boolean x
Return the boolean negation of integer representation of boolean x
Return the integer representation of boolean x or'd with boolean y
Returns a pointer in memory to a string "It's Alive!!!"
Returns a pointer in memory to string x