Hide
Scraps
RSS
Showing all entries tagged with: Guide

Teaching old C code new tricks with Nim

8th September 2023

Recently I was met with an interesting problem when wrapping a C library in Nim. The library in question was MAPM, an older but quite complete library for dealing with arbitrary precision maths. Unfortunately the library doesn’t have much in the way of error handling. If something goes wrong it almost always writes to stderr and returns the number 0. And to be fair, there isn’t a whole lot that can go wrong in…


Setting up a Nim server for dummies

8th June 2023

Nim is a great candidate for server development, but if you want to run your own server and are new to the world of server management or Linux there can be a daunting amount of information to consume in order to do it right. In this article I’ll give a quick rundown of setting up a small server capable of running your Nim server in a safe way. It is much more low-level than many…


Wrapping C libraries in Nim

17th April 2023

As we discovered in my last article, Nim will by default generate C code and then call on a C compiler to actually produce a binary. This might seem like an odd choice, especially in the age of LLVM. However it’s actually not uncommon for languages to compile or transpile into another language. Initially the choice to not use LLVM was simply because it wasn’t as mature back when Nim was created. Though going through…


Dynamic libraries in Nim

20th February 2023

This is a question which has been asked in various places over the years, and recently on the forum in multiple separate threads. Seeing how I’ve built commercial software with Nim dynamic libraries, I thought I’d chime in with my knowledge. But since there are multiple threads out there and this is a large-ish topic I figured it would be better to do it as a post on here.

The problem

As you’re probably aware Nim…


Asynchronous programming in Nim

3rd September 2021

In the previous article we got a small primer on various kinds of multi-tasking, in this article we'll have a look at possibly the simplest form of this. Namely asynchronous execution. As discussed in the last article asynchronous execution is a way for our programs to tell the hardware to do something, and then do something else while waiting for it to complete the operation. This is great when we want to for example…