Replies: 1 comment
-
|
Currently, no. You have to call a function pointer of a specific type. Generally, we want to avoid referencing JavaScript values in Zig since we have no garbage collection there. A theoretical implement of your example would lock both What we do perhaps is to have a Zig function that emits an const zigar = @import("zig");
pub fn say_hello() !void {
try zigar.js.emit(.log, .{ .message = "Hello from Zig!" });
}import { __zigar, say_hello } from 'zig/test.zig';
__zigar.on('event', (type, arg) => {
switch (type) {
case 'log':
console.log(arg.message.string);
break;
}
});
say_hello();Of course, we're using console here only as an example. You'd use |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, not sure if it is somewhere in the docs...but is it possible to make calls into the JS host environment in a generic way?
If not, what would be the best way to do this?
I also couldn't figure out how to introduce these definitions into the runtime environment:
I can see the entry is the generated by looking at the resulting wasm file, but not sure how to pass it as an import function/object prior to the WebAssembly instance initialization.
Any help, clarifications or direction would be greatly appreciated.
Many thanks!
Beta Was this translation helpful? Give feedback.
All reactions