按照文档,我可以运行 Polyglot 应用程序,其中起始语言是Java,目标语言是C++,它位于一个单独的源文件中。
我想知道如何将一些参数从 Java 传递给 C++。
代码示例
起始语言 (Java)
import org.graalvm.polyglot.*;
import java.io.File;
import java.io.IOException;
public class HelloPolyglot {
public static void main(String[] args) throws IOException {
File file = new File("polyglot"); // the path to the file
Source source = Source.newBuilder("llvm", file).build();
Context polyglot = Context.newBuilder().allowAllAccess(true).build();
Value cpart = polyglot.eval(source);
cpart.executeVoid();
}
}
目标语言 (C++)
#include <iostream>
using namespace std;
int main(int argc, char** argv){
cout << "You have entered " << argc
<< " arguments:" << "\n";
for (int i = 0; i < argc; ++i)
cout << argv[i] << "\n";
return 0;
}
先感谢您。