Chapter 4 - Working with Tables
Errata
Table of Contents
Working with Tables - 43
- Storing Data Using Tables - 43
- Creating and Indexing Tables - 44
- Clearing an Element from a Table - 44
- Shortcuts for String Keys - 45
- Creating Populated Tables - 45
- Using Tables as Arrays - 46
- Creating an Array - 46
- Getting the Length of an Array - 47
- Adding Elements to an Array - 48
- Removing Elements from an Array - 49
- Sorting the Elements of an Array - 50
- Using Tables as Namespaces - 51
- Creating a util Namespace - 51
- Adding Functions to util - 51
- Storing an Existing Function - 51
- Defining a New Function - 52
- Object Oriented Programming with Tables - 52
- Creating a Non-Object-Oriented Counter - 53
- Using Tables as Simple Objects - 53
- Using : to Call Object Methods - 54
- Defining Functions Using : - 54
- Making a Better Counter - 55
- Extending Tables with Metatables - 56
- Adding a Metatable - 56
- Defining Metamethods - 57
- Defining Basic Arithmetic using __add, __sub, __mul, and __div - 58
- Defining Negation using __unm - 59
- Creating Meaningful Output with __tostring - 59
- Concatenating Tables Using __concat - 60
- Exploring Fallback Tables with __index - 60
- Catching New Keys with __newindex - 62
- Bypassing Metatables - 63
- value = rawget(tbl, key) - 63
- rawset(tbl, key, value) - 63
- Summary - 63