mirror of
https://github.com/bytedream/litbwraw.git
synced 2025-06-27 02:10:33 +02:00
add example crates
This commit is contained in:
15
example-library/nodejs.js
Normal file
15
example-library/nodejs.js
Normal 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();
|
Reference in New Issue
Block a user