Chapter 8. Interfacing with other languages

This chapter covers

  • Getting to know Nim’s foreign function interface
  • Distinguishing between static and dynamic linking
  • Creating a wrapper for an external C library
  • Using the JavaScript backend
  • Wrapping JavaScript APIs

For many years, computer programmers have been writing software libraries in various programming languages. Many of these libraries have been in development for a very long time, accumulating features and maturing over the years. These libraries are not typically written in Nim; instead, they’ve been written in older programming languages such as C and C++.

When writing software, you might have required an external C library to perform a task. A good example of this is the OpenSSL library, which implements the SSL and TLS protocols. It’s primarily used for securely transferring sensitive data over the internet, such as when navigating to a website using the HTTPS protocol.

Many of the HTTP client modules in the standard libraries of various programming languages, including Nim’s, use the C library to transfer encrypted data to and from HTTP servers securely. It’s easy to forget that this library is used, because it’s usually invoked behind the scenes, reducing the amount of work the programmer needs to do.

8.1. Nim’s foreign function interface

8.2. Wrapping an external C library

8.3. The JavaScript backend

8.4. Summary

sitemap