With this book, you have learned the foundations of not just Lua, but of programming. You have access to the building blocks of very advanced code. All you have to do now is use the knowledge you have gained for new projects.
How to Practice
You’re familiar with the old saying practice makes perfect, and it should be no surprise that it applies as much to programming as to anything else. You cannot hope to become an efficient, comfortable programmer without weeks and weeks, and then months and months, of practice. The key is to find an excuse to use Lua. Make Lua work for you. Make it do stuff that you don’t feel like doing yourself. You have already learned how to use Lua to build and release your software, for example, so find other small tasks for Lua to do for you.
Note
If you want to create a GUI application in Lua, there are several toolkits you can use. Obviously, there is LÖVE itself, but it is intended as a game engine. For a generic GUI libraries providing common widgets like buttons and text fields, try TekUI at tekui.neoscientists.org, SUIT for LÖVE at github.com/vrld/SUIT, and Luce at github.com/peersuasive/luce.
Sometimes, learning new tricks on computers seems like a waste of time. For instance, you already know how to start a basic LÖVE project, but imagine how much you would learn by creating a Lua script to generate fresh project directories and even basic file starters. Find common, everyday tasks that you find yourself doing frequently, and spend time programming an application or command to help you accomplish them. The task itself may only take you a minute or two to do, and programming a solution might take you a few days, but you’ll learn a lot, and after the 300th time of doing the same old task, you’ll thank yourself for the application you created. And after your 300th script, you won’t even be able to remember when you didn’t think like a programmer.
How to Learn
Of course, practice in principle is one thing, but actually generating code that functions is another. Sometimes, you will want to do something in code that you have no experience with, and no reference point for where to begin.
The Lua and LÖVE functions you have learned from this book were relatively easy for you to discover because this book presented them to you and showed you how to use them.
A big part of learning a programming language is learning what functions it has to offer you. Lua functions are documented in full at www.lua.org/manual/5.3 , in the Index section. Every function of Lua is listed and documented. For LÖVE, see love2d.org/wiki/love.
The Lua site is highly technical and doesn’t provide many examples, so it can be difficult to understand. However, Programming in Lua by Roberto Ierusalimschy (Lua.org, 2016), the principle architect of Lua itself, is an excellent resource for both the language and usage of its functions.
How to Read Technical Documentation
Any time you are about to use a new library (like inifile or table_save.lua) or even a new programming language, you should go to its technical documentation or to the source code itself and read it. You don’t necessarily have to read it like a novel, but you should have a passing familiarity with what the library or language provides you so that you know where to start, and you don’t spend a day implementing something that a library gives you for free.
As you’ve probably started to notice from writing them yourself, functions have two parts: input and output. As long as you keep that in mind, you can read technical documentation easily and use any function you dig up.
For example, assume that you are using Lua to program an interface to help users create a password that is at least 15 characters long. You need a way to count the letters in a string (the string foo contains three letters, the string foobar has six, and so on).
You already know some tricks that count items. For instance, you can find the number of items in a table with the #table notation, and you know how to create loops with counters. You could probably spend some time researching this problem and find a reasonable example online on how to implement it. But what you’d also find is that Lua already has a function called string.len that solves your problem.
To read how to use this function, find out those two essential components of every function: input and output. The input to a function is an argument, so (s) is its input. The documentation says that s is a string.
The output of a function is what it returns. Sometimes this is a literal return statement in its code, while other times it’s variables that get set while the function runs. In this example, the function returns the length of s, so you can expect an integer.
Use this learning method with all the technical documentation for Lua, LÖVE, and any other programming library or language that you are using.
Leveraging Open Source
Finally, Lua is open source. It has a worldwide community of users who openly communicate with one another about how the language is used, how common problems are solved, how specific functions work, and much more. If you’re not used to the culture of open source, then you’re probably not accustomed to this kind of sharing of knowledge. It’s a conversation, so join in, be polite and respectful, answer questions when you can, and ask well-researched questions with lots of context and code samples when you need help.
Learning Other Languages
You should spend more time with Lua once you have finished this book, at least until you are comfortable programming in the language. Lua is a simple, efficient, and cohesive language, so there are relatively few functions to learn. It’s a manageable language, especially when compared to bigger ones like Python, Ruby, Java, and PHP. That’s a feature that you’ll come to appreciate after trying more complex languages.
On the other hand, Lua’s minimalism renders a sparse language, meaning that you have to create your own functions for things that other languages have as built-in features.
Some languages, like Python and Java, are so widely known that it seems everything is already done for you; all you have to do is download a library, and most of the hard work is done. Of course, this is not true in practice, because every program ends up requiring customization, but the more popular a language, the greater the choice you have between libraries and frameworks.
The good news is that once you’re comfortable enough with Lua to sit down and code something from scratch in an afternoon or two (or seven, depending on the size of the project!), you’ll find that learning a new language comes easy. Once you internalize the “grammar” of programming, learning the vocabulary is easy, and often something you can do as you code.
The question is: do you need to learn another language?
Learning a second or third programming language can be useful primarily for compatibility. For instance, if you want to write a plugin for an application that only offers plugin support for Python, then it’s useful to know Python. If you want to write native applications for Android, then you should learn Java. If you want to get a job at a company that has built its business on Ruby, then you should learn Ruby.
You might hear murmurings that one language isn’t good for one task, and that another language is better for other tasks, as if programming languages were built with a specific set of applications in mind. While it’s true that sometimes a language is designed in such a way that its available functions happen to favor one type of job or another, strictly speaking, a programming language is just an interface to machine instructions. Don’t be confused by the mélange of choice. Learning additional programming languages add to your perspective on code, your toolkit for getting things done efficiently, and your curriculum vitae when looking for work.
And learning a new language can be done with this book. LÖVE is specific to Lua, but most major languages have game engines. And even if your target language lacks a game engine, you can still use the structure of these lessons to learn. Start with simple programs, like a dice roller, and then try something more ambitious, like a simple card game. Explore arrays and other data constructs. Learn to read data from disk and how to write it back out. Learn to write your own libraries or modules and how to require or include them. And finally, try a bigger project like Battlejack or Permadungeon to stretch your understanding of the language.
Homework
As this book’s final assignment, you are encouraged to sit down with a pen and some paper to design the next game or application you want to create with Lua. Spend some time on it. Design something useful and slightly more ambitious than you think you can manage.
Next, break the application down into learnable components. You haven’t learned how to drag and drop GUI elements, for example, and yet you know everything you need to make it work (hint: mousepressed combined with a custom collide function ought to work). Look at your long-term goals and write small applications that may not even serve a purpose other than to teach you a new trick or two.
Once you have learned all the parts of what you want to build, then it’s just a matter of implementing it all in one big code base.
Whether or not you feel like you understand everything there is to understand about Lua, programming, game design, Linux, and software development in general, you are a programmer now. So go program something!