Communicating with a dynamic scripting language
D's features also lead to easy integration with dynamic languages. It can host a dynamic type as well as dynamic objects.
Getting ready
To begin, download bindings to a scripting language. Here, we'll use the one I wrote whose syntax is inspired by both D and JavaScript. It was written with the goal to blur the line between the D code and the script code—the scripting language's dynamic type can also be used in D itself. Download jsvar.d
and script.d
from the following website:
Build your program with all three files on the command line, as follows:
dmd yourfile.d jsvar.d script.d
How to do it…
Let's execute the following steps to communicate with JavaScript:
Create an object to wrap the script engine with a friendlier API.
Prepare the script engine by passing data and function references to it. It may be necessary to wrap D functions in transforming functions to match the script engine's layout.
Use
opDispatch
and...