How does code written in one language get called from another language

后端 未结 7 1801
余生分开走
余生分开走 2021-01-31 06:25

This is a question that I\'ve always wanted to know the answer, but never really asked.

How does code written by one language, particularly an interpreted language, get c

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 07:12

    You can also integrate the two environments without having to compile the interpreter's library inside your executable. You keep your exe and the Scheme exe as separate programs on your system. From your main exe you can write your Scheme code to a file then use system() or exec() to run the scheme interpreter. You then parse the output of the scheme interpreter.

    The approach suggested above keeps the exes separate and you do not have to worry about 3rd party dependencies, they can be significant. Also problems stay contained in one exe or another.

    If running a separate exe does not satisfy your performance requirements you can devise a protocol where the Scheme interpreter becomes a server. You need to write some Scheme functions that wait for input on a socket or file, eval that input then output the result to the same socket or a different file. Another iteration of this is to look at existing servers that may be running your interpreter already, for example apache has modules that allows code to be written in many languages.

提交回复
热议问题