Nim has all the language mechanisms needed to smoothly interoperate with C and C++. The rather large collection of wrapped C libraries (and that’s only those in the standard libs) is also a testament to this fact. In this article I explain my personal findings testing out the waters of wrapping a simple C library.
The basic approach to wrapping a simple C library is:
- Install Nim.
- Install c2nim using Babel or manually clone c2nim from github and build it.
- Use c2nim to translate the C header file(s) to a so called Nim wrapper.
- Make a small test showing it works.
- Write a so called “impure” intermediary library that uses the wrapper (next article)
- Make a test green and declare Victory (next article)
Okidoki… (roll up sleeves)