WOLFRAM LANGUAGE TUTORIAL
Introduction to WSTP
In many cases, you will find it convenient to communicate with external programs at a high level and to exchange structured data with them.
On almost all computer systems, the Wolfram System supports the Wolfram Symbolic Transfer Protocol (WSTP) communication standard, which allows higher‐level communication between the Wolfram System and external programs. In order to use WSTP, an external program has to include some special source code and a WSTP library, which are usually distributed with the Wolfram System.
WSTP allows external programs both to call the Wolfram Language and to be called by the Wolfram Language. "WSTP and External Program Communication" discusses some of the details of WSTP. By using WSTP, you can, for example, treat the Wolfram Language essentially like a subroutine embedded inside an external program. Or you can create a front end that implements your own user interface and communicates with the Wolfram Language kernel via WSTP.
You can also use WSTP to let the Wolfram Language call individual functions inside an external program. As described in "WSTP and External Program Communication", you can set up a WSTP template file to specify how particular functions in the Wolfram Language should call functions inside your external program. From the WSTP template file, you can generate source code to include in your program. Then when you start your program, the appropriate Wolfram Language definitions are automatically made, and when you call a particular Wolfram Language function, code in your external program is executed.
|Install["command"]||start an external program and install Wolfram Language definitions to call functions it contains|
|Uninstall[link]||terminate an external program and uninstall definitions for functions in it|
Calling functions in external programs.
This starts the external program
, and installs Wolfram Language definitions to call various functions in it.
Here is a usage message for a function that was installed in the Wolfram Language to call a function in the external program.
When you call this function, it executes code in the external program.
This terminates the
You can use WSTP to communicate with many types of programs, including with the Wolfram Language itself. There are versions of the WSTP library for a variety of common programming languages. The J/Link system provides a standard way to integrate the Wolfram Language with Java, based on WSTP. With J/Link you can take any Java class and immediately make its methods accessible as functions in the Wolfram Language.