C is the lingua franca of programming languages. Anything your system can do—such as access the internet, play an audio file, or generate real-time GPU-based 3D graphics—you can do via C code linked with the right libraries. Lua takes advantage of C’s universality by making it easy to share C functionality with Lua code. That’s what we’ll do in this chapter.
The example code in this chapter is split across two pairs of files. The first pair contains the files eatyguy1.c and eatyguy1.lua, whereas the second pair, in a rather predictable manner, contains the files eatyguy2.c and eatyguy2.lua. Thus continues the saga of the EatyGuy example code, which will grow iteratively throughout the remainder of this book, consistently with filenames that begin with eatyguy<num>. I hope this naming scheme makes it easier for you to see where each iteration fits into the big picture. It also reflects the typical iterative nature of software projects.
Let’s begin by giving EatyGuy the ability to draw text characters with different background colors. We’ll write C code that creates the function listed in Table 2-1 in Lua.
||Change the terminal’s current background color to