Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

how can i set a struct as ExternalGlobal like global in js #110

Open
hunjixin opened this issue Mar 22, 2019 · 4 comments
Open

how can i set a struct as ExternalGlobal like global in js #110

hunjixin opened this issue Mar 22, 2019 · 4 comments

Comments

@hunjixin
Copy link

how can i set a struct as ExternalGlobal like global in js

@twitchyliquid64
Copy link
Contributor

I'm not sure I understand the question. If you mean how can you call into Go code from a wasm module, please have a look at TestHostCall in exec/call_test.go - this describes how you can add in a native function to a wasm.Module so you can call it from wasm code.

Basically, you manipulate the fields of wasm.Module to add in whatever functions or tables you like.

@hunjixin
Copy link
Author

yes,function is ok,and simple variable is alson work,but i want to access a more global complex struct variable for other module

@hunjixin
Copy link
Author

@twitchyliquid64 .
i write code by rust and then converto to wasm.
I want to set a global object in wagon , and access it in rust. how to write the code

@twitchyliquid64
Copy link
Contributor

I think you can only pass 64bit arguments between function invocations. Anything else will need to be passed as a pointer/index and then use linear memory / tables.

For instance, you could write your rust code to save an object in linear memory 0x0000 - 0x2000, then use vm.Memory() to read that section of memory.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants