You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Embed C in Java Using GraalWasm](guides/embed-c-in-java.md)
226
+
-[Embed C in Java Using GraalWasm](https://github.com/graalvm/graal-languages-demos/tree/main/graalwasm/graalwasm-embed-c-code-guide){:target="_blank"}
227
227
-[Embedding Languages documentation](../embedding/embed-languages.md)
> The exported functions must be prefixed by `_`. If you reference that functionin,for example, the Java code, the exported name should not contain the underscore.
49
-
50
-
It produces a standalone file _floyd.wasm_ in the current working directory.
51
-
52
-
3. Add dependencies. The GraalVM SDK Polyglot API can be easily added as a Maven dependency to your Java project.
53
-
The GraalWasm artifact should be on the Java module or class path too. Add the following set of dependencies to the project configuration file (_pom.xml_ in the case of Maven).
54
-
55
-
- To add the Polyglot API:
56
-
```xml
57
-
<dependency>
58
-
<groupId>org.graalvm.polyglot</groupId>
59
-
<artifactId>polyglot</artifactId>
60
-
<version>${graalwasm.version}</version>
61
-
</dependency>
62
-
```
63
-
- To add GraalWasm:
64
-
```xml
65
-
<dependency>
66
-
<groupId>org.graalvm.polyglot</groupId>
67
-
<artifactId>wasm</artifactId>
68
-
<version>${graalwasm.version}</version>
69
-
<type>pom</type>
70
-
</dependency>
71
-
```
72
-
73
-
4. Now you can embed this WebAssembly functionin a Java application, for example:
74
-
75
-
```java
76
-
import org.graalvm.polyglot.*;
77
-
import org.graalvm.polyglot.io.ByteSequence;
78
-
79
-
// Load the WebAssembly contents into a byte array
Value mainFunction =context.getBindings("wasm").getMember("example").getMember("floyd");
94
-
mainFunction.execute();
95
-
context.close();
96
-
```
97
-
98
-
5. Compile and run this Java application with Maven as usual.
99
-
100
-
### Related Documentation
101
-
102
-
- [Embedding Languages documentation](../../embedding/embed-languages.md)
103
-
- [GraalWasm](../README.md)
9
+
The content was moved to [Graal Languages - Demos and Guides repository](https://github.com/graalvm/graal-languages-demos/tree/main/graalwasm/graalwasm-embed-c-code-guide).
0 commit comments