add example crates

This commit is contained in:
2024-09-29 18:23:50 +02:00
parent da63980914
commit f116e435ec
15 changed files with 782 additions and 3 deletions

15
example-library/nodejs.js Normal file
View File

@ -0,0 +1,15 @@
async function main() {
const wasm = await import('./target/wasm32-unknown-emscripten/debug/example-library.js');
const module = {
print: (str) => console.log(str),
printErr: (str) => console.error(str),
}
const exampleLibrary = await wasm.default(module);
const luaInstance = exampleLibrary.ccall('lua_new', 'number', [], []);
const luaExecute = exampleLibrary.cwrap('lua_execute', null, ['number', 'string']);
luaExecute(luaInstance, 'print("Hello from WebAssembly Lua!")');
}
main();