当源文件用几种不同的编程语言编写时,我试图弄清楚如何在源文件之间共享函数。有没有办法在三个不同的源文件中共享用三种语言编写的函数,如下所示?我希望用每种语言编写的函数都可以从其他语言访问。
(澄清一下,所有源文件都在同一个文件夹中。)
Java 文件:
public class JavaFile{
public static String generateStringFromRegex(String theRegex){
//native Java function, implement this using xeger
}
public static String generateRandomString(String theString){
//return the result from the corresponding Javascript function
}
public static int getFileText(String filename){
//return the result from the corresponding C++ function
}
}
Javascript 文件:
function getFileText(fileName){
//call the corresponding C++ function and return the value
}
function generateRandomString(theString){
//native Javascript function
}
function generateStringFromRegex(int1, int2){
//call the corresponding Java function and return the value
}
C++ 文件:
#include<string>
int main(){
}
string generateRandomString(string theString){
//call the corresponding Javascript function and return the value
}
string generateStringFromRegex(string theRegex){
//call the corresponding Java function and return its value
}
string getFileText(string fileName){
//native C++ function: get the text of a text file
}