Lua Adam

From Training Material
Jump to navigation Jump to search


Interspersed throughout all of the listed lessons will be exercises and puzzles/challenges to keep the client involved and attentive, as well as to provide myself with insight into potential traps they might find themselves in when coding in Lua, and any deficiencies in their understanding or my own lesson planning.

Primarily because this structure is untested before this first session, I will be treating this outline as a checklist and a guide more than a strict lesson plan.

Day 1

Most defined day. Covers in additional detail all weak spots client has with the language, as per short interview.
Various "gotchas" will be mentioned and covered where the relevant feature is discussed e.g. `nil` and `NaN` as Table indices.
These, as well as general Lua program design tips, will be consolidated into a single section at the end, for quick reference going forward.

Based on the client's experience and ability, this day may run short. If that should happen, Day 2 material will be used until the session is over.
Any extra time added to Day 2 will be used to explore the remaining content in more depth and detail.

Prep

  • Introductions & Training Outline
  • Installing dev environment (IDE or simply text editor + CLI tools)
  • Installing LuaRocks
  • Quick reference links and tools

Lua Primer

  • naming conventions
  • data types
  • environment and scope
    • upvalues vs. local variables
  • conditionals
    • ternary "operator"
  • loops
    • while
    • numeric for
    • generic for
  • goto
  • error handling

Tables

  • as Arrays
  • as Dictionaries
  • as "Tables"
    • "Objects without Classes"
  • basic __index
  • weak Tables

Advanced Functions

In no fixed order:

  • multiple returns
  • first-class values
  • named arguments
  • variadic arguments
  • metamethods
  • closures
  • currying
  • tail calls
  • custom iterators

Gotchas

Generally, this section will cover the most common pitfalls and bug sources in Lua code, as well as easy optimizations to make.

  • string buffering
  • Table oddities
    • "invalid" indices/keys
    • nil values
    • comparisons
    • __index shortcut
    • raw* functions
  • method syntax
  • string methods on inline strings
    • ambiguous syntax.
  • explicit `false`
  • type coercion
  • multi-variable expressions
  • __VERSION differences!

Day 2

This day will primarily be discussion of the the Standard Libraries with special focus on the `string` library, mainly Lua Patterns.

In 5.2 Reference Manual order:

  • "basic" library
  • `coroutine`
  • `package`
  • `string`
  • `table`
  • `math`
  • `bit32`
  • `io`
  • `os`
  • `debug`

The remaining time of this day will be spent on the C-Side Lua API and external packages with LuaRocks.

TODO: Expand this section. (I don't know anything of the C-Side of Lua as of writing this sentence.)

Day 3

This day will be a series of "practical" VM implementations in Lua, as I believe VMs to touch on every possible subject a programmer might have to deal with in any real-world scenario.

On a per-client basis, this day in whole or in part might instead be spent working with their existing codebase to either refactor or convert to Lua, based on the lessons and tips from the previous sessions.

Note: This section specifically is still significantly WIP.

  1. HackVM and SuperHack
  2. Synacor Challenge - Used with permission from Eric Wastl
  3. Famicon Emulator