View on GitHub

Tech, Games and Whisky

The Sebr's Blog

Single file C library

|

It is generally easy when you work on a javascript app to integrate a third party library. Most of the time, it is just using NPM or Bower then you include the usually single js file and you are good to go. Often, using a package manager is a superfluous step. Download the lib directly or link to a CDN and TADA: it works.

The burden of making a Javascript library easy to integrate is often put on the maintainer of the library itself. Nolan Lawson wrote a great piece on this exact subject and how Lodash has a nice way to solve this issue. This snippet of code in the lodash depot gives a good idea of what John-David Dalton (the maintainer of Lodash) must cope with to support every Javascript module systems under the sun.

Welcome to the C/C++ world

I used to program a lot in C++. And trust me it is much more difficult to integrate third party libraries in that “world”. You always end up cursing and swearing and asking yourself million questions:

  • Is the library precompiled?
  • If so does it work with Visual Studio 11?
  • Why doesn’t it support MacOS?
  • Why are there 1 million header files in Qt?
  • How come do I have to pay? What is LGPL? Will my code be contaminated with the GPL plague?
  • Why is XCode not able to link with libXml?

Single file library - STB

The mirror of Javascript “single file third party library” is the C/C++ Single File library. The poster child for these libraries are the incredibly useful, well maintained and easy to use: STB. These libraries created by Sean Barrett cover a lot of different subjects from image manipulation, to fonts rendering and to all sorts of data structure utility.

Sean has a great single library howto document explaining how he packages his libraries.

Other Single File Libraries

It seems STB has helped to create a Single file library movement. Sean has a big list of such libraries on his site.

Some interesting libraries, in my opinion, are:

Miniz

This library is a z-lib replacement in a single file. Incredibly easy to use, this is what we chose for our Zip support in Stingray Editor.

Nuklear

I have already written about my love of UI and especially Immediate GUI. Nuklear is a single file IMGUI C library! It even uses stb for fonts and text rendering.

stb

stb2

Debuginator

A single file game debugger menu. This library was used by Fat Shark to ship their latest game: Warhammer End Times - Vermintide (which is a game that uses Stingray as its game engine).

noc turtle

This last library is used to render images using a CFDG like grammar. It is interesting both for its tricky usage of macros to generate coroutine like code and also because it was used to produce art for the Blowfish Rescue game.

noc