Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

Sparse arrays

Arrays can be sparse, meaning an array can have a hole in it. Elements can be assigned to index 1 and 2 of an array, leaving 3 and 4 blank and then assigning elements 5 and 6. Any hole in the array will have a default value of nil, as the following code segment demonstrates:

arr = { }arr[1] = "x"arr[2] = "y"-- arr[3] is nil by default-- arr[4] is nil by defaultarr[5] = "z"arr[6] = "w"for i=1,6 do    print (tostring(arr[i]))end

This implies that setting the value of an existing index to nil will introduce a hole in the array. These holes can sometimes cause unexpected issues.

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

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content