Get in Touch

Course Outline

Introduction to Lua

  • A brief history
  • Lua's goals, features, and non-goals
  • Resources for Lua documentation and tutorials
  • Installing the Lua interpreter
  • Setting up and using LuaRocks

Basic syntax and semantics

  • Identifiers
  • Comments and block comments
  • Global variables and enforcing strictness
  • Local variables
  • Standalone programs and program arguments
  • Compilation units, chunks, expressions, and semicolons

Data types and data structures

  • Basic types: nil, boolean, number, string
  • Object types: function, userdata, thread, table
  • References and objects versus basic values
  • The importance of tables in Lua

Introduction to tables and their versatility

  • Tables as associative arrays
  • Tables as numeric arrays and sequences

Basic control structures

  • The if, then, elseif, else, end structure
  • The while loop
  • The repeat loop
  • The simple for loop

Error handling

  • Return values versus exceptions
  • Converting a return value to an exception
  • Converting an exception to a return value
  • Error levels

Example programs

  • Polynomial evaluation
  • Breadth-first search
  • Additional exercises

More about functions

  • Named arguments
  • Object-oriented calls
  • Closures
  • Currying
  • Tail calls
  • Multiple assignment and return
  • Varargs

Iterators and co-routines

  • The generic for loop
  • Stateless versus stateful iterators
  • Differences between iterators and co-routines

Metatables and metamethods

  • The set example
  • The __tostring metamethod
  • Arithmetic metamethods
  • The __index and __newindex metamethods
  • The __len metamethod

Modules and packages

  • Using modules
  • Creating modules
  • Organising modules into packages

Advanced tables

  • Tables for queues and stacks
  • Tables describing graphs
  • Matrices as tables
  • Linked lists as tables
  • String buffers

Metatables through examples

  • Proxies
  • Read-only tables
  • Memoisation
  • Dynamic programming with memoisation
  • The Fibonacci example

Environments

  • The relationship between global variables and environments
  • Free variables
  • The _ENV table and the _G table

More about modules

  • Different approaches to creating modules
  • Modules that alter behaviour
  • Module initialisation and arguments
  • Using environments to implement safe modules

Advanced iterators and co-routines

  • Producer, consumer, and filter patterns
  • Wrapping co-routines to obtain iterators
  • A stateless iterator for linked lists

Contributing to the Ecosystem

  • Uploading packages to MoonRocks

Functional paradigm in Lua

  • The map function
  • The reduce or fold function

Object-oriented Programming

  • Different approaches to OOP
  • Different approaches to inheritance
  • Examples

A walkthrough of the Lua Standard Libraries

Compilation

  • Compilation
  • Eval
  • The relationship with the environment
  • Binary chunks

Garbage collection

  • Weak tables
  • Finalisers and the __gc meta-method

Lua bytecode and virtual machine

  • Generating bytecode from source code
  • Reading and analysing bytecode
  • A quick tour of the Lua VM source code

C modules

  • Calling C from Lua
  • Search path and loading of C modules

Calling Lua from C

  • The Stack
  • Error handling
  • Continuations

Handling Lua values and types from C

  • Arrays
  • Strings
  • Userdata
  • Metatables
  • Object-oriented calls
  • Light userdata

Memory management

  • Allocators
  • GC API

Threads in Lua

  • Co-routines versus threads
  • Real multi-threading and Lua states

Requirements

Familiarity with at least one other programming language and some programming experience are required. Optionally, prior experience with other scripting languages will make it easier to grasp Lua.

 21 Hours

Number of participants


Price per participant

Provisional Upcoming Courses (Require 5+ participants)

Related Categories