Skip to Content
Beginning Lua Programming
book

Beginning Lua Programming

by Kurt Jung, Aaron Brown
February 2007
Beginner
672 pages
15h 34m
English
Wrox
Content preview from Beginning Lua Programming

Chapter 10. Looking Under the Hood

This chapter covers various ways of looking at the inner workings of Lua. To continue the automotive metaphor of the title, you can write many useful programs without knowing the things in this chapter, just as you can drive a car without knowing how to change the oil. However, the knowledge and techniques in this chapter will help you find bugs, and let you do things with Lua that otherwise wouldn't be possible. You'll learn about the following:

  • Using bytecode

  • Controlling Lua's memory management

  • Understanding the implementation of tables and strings

  • Looking directly inside functions to see and alter their local variables

  • Tracing the execution of your code on a call-by-call, line-by-line, or instruction-by-instruction basis

Bytecode and luac

As mentioned in Chapter 3, before Lua can execute source code, it needs to compile it into bytecode, which is then interpreted by the bytecode interpreter. Another name for the bytecode interpreter is the virtual machine, because it's kind of like an imaginary computer (imaginary in the sense no one has ever built one out of silicon —it's just simulated by your real computer). Lua comes with two programs: the command-line interpreter lua, and the bytecode compiler luac. The main purpose of luac is to compile Lua source code to bytecode and save that bytecode to a file (so it can be run later), but it can also output a human-readable listing of the bytecode.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Lua Quick Start Guide

Lua Quick Start Guide

Gabor Szauer
The Go Programming Language

The Go Programming Language

Alan A. A. Donovan, Brian W. Kernighan

Publisher Resources

ISBN: 9780470069172Purchase book