Interactive Programming… in C

Published on 2018-01-17 by Mark VandeWettering

I’ve been kind of interested in a type of “livecoding” where changes to a code base are immediately reflected in a running program. I’ve seen Inigo Quilez (author of the famed shadertoy.com) do this with a scaffold that he wrote using OpenGL. Literally as he types new shader code, the changed shader is loaded and executed, and the new graphic image forms the background of his editor.

You can see an example of this here:

I started working on a similar framework, and got the basics working (except that I didn’t write my own editor, but merely ran vi in a window and updated the fragment shaders running in a separate window) but today I discovered this kind of cool idea: doing the same sort of thing in C.

Chris Wellons wrote on his blog back in 2014 about a set of techniques that could be used to do the same sort of interactive stuff in C.  The basic idea is to write a framework which constantly monitors a shared library, and when it is updated, reloads the library.  If it is not, then it calls an “update” loop.  I don’t think this is helpful for all sorts of programs, and there are a few details to be sorted, but it’s kind of cool.  I can imagine giving this a try on one or two projects that I’ve been pondering.  Archived for future reference.

 

Addendum: David Parrot posted this to my twitter feed:

In case twitter integration fails, it’s a link to Casey Muratori’s Homemade Hero on instantaneous live coding. I haven’t had a lot of time to watch the videos yet, but they seem very cool.