Pipes are one method of interprocess communication in the Unix world, the other being sockets. The differences are that pipes are more simple to set up and use but more narrow in scope. Pipes are unidirectional, having one writer and one reader, and operate on a ‘first in first out’ (or FIFO) principle – i.e. the first bit of data you put in is the first you get out; if I put ‘hello world’ into a pipe I will receive a ‘h’ first and the ’d’ last.
I’ve been working a bit with pipes in Python, using the subprocess module to kick off a couple of processes, a client and a server, and using pipes to redirect their input and output in such a way as to test them. I thought it might be an idea to write about using pipes primarily from a Python viewpoint, with a view especially to clarifying things like blocking and buffering. In the course of this tutorial we will develop a testing tool for a pair of programs.
Recently I’ve ben playing around with developing a zoomable and panning image viewer using Emscripten and its proved to be a good exercise in accessing parts of the page’s HTML document outside of the Emscripten run-time. The end goal is to provide a JavaScript API to an image viewer, consisting of an ImgViewer object and a single method: ImgViewer(image, canvas) – sets up the viewer to use the HTMLCanvasElement, canvas and show a pannable and zoomable copy of the HTMLImageElement, image ImgViewer.changeImage(image) – changes the image shown by the image viewer to the HTMLImageElement, image The main bit of ground here that I didn’t cover in my previous tutorial on Emscripten and SDL2, is how to somehow get the image data from the HTMLImageElement to be accessible from the Emscripten compiled C program.
Emscripten is a compiler that allows you to take standard C/C++ and compile it to JavaScript, making it possible to port your C/C++ programs and run them in any modern browser. This tutorial series aims to be your guide and lead you to using the SDL2 library to implement all the basic components of a 2D game; showing an image, moving an image and listening for user input, and enabling you to make a game like this example of ‘snake’ with relative ease in C/C++, all without writing a single line of JavaScript.