Skip to content

Teaching old C code new tricks with Nim

peterme.net
22 pointskindaAnIdiot2 comments
On HN

Comments

This is a good example of cross language interop making sense, and of considering the vast array of old C libraries to be something worth remembering - and maybe putting in your toolkit. Wasm seems to cover a lot of this use case too, and any language with a good enough FFI. Interop is a priority for nim, though, and is pretty delightful to put to the test.

Indeed, the FFI in Nim is really great, and with ARC it's so much easier to properly integrate with the malloc/free lifecycle that most C libraries use. The full wrapper for this project is here: https://github.com/PMunch/mapm-nim and I've already converted a calculator program of mine to using this instead of floats by simply just swapping out the type. Checked with Valgrind and besides finding some bugs in another external library it was happy.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.