Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Lua Quick Start Guide

You're reading from  Lua Quick Start Guide

Product type Book
Published in Jul 2018
Publisher Packt
ISBN-13 9781789343229
Pages 202 pages
Edition 1st Edition
Languages
Author (1):
Gabor Szauer Gabor Szauer
Profile icon Gabor Szauer

Arrays

An array is a contiguous chunk of memory; some programming languages guarantee that the memory will be contiguous. In Lua, an array might use a linear chunk of memory if the following apply:

  • The table has only numeric indices
  • The numeric indices start from one
  • At least half of the indices are not nil
How tables are implemented is dependent on the internals of Lua. This is not something you usually have to concern yourself with, but if you are interested, the topic is described in detail at http://www.lua.org/doc/jucs05.pdf.

For now, assume that an array is defined as a table that is indexed only numerically, starting with index 1. By this definition, the following code demonstrates how to use a table as an array:

arr = {}

arr[1] = "x"
arr[2] = "y"
arr[3] = "z"

for i = 1,3 do
print(arr[i])
end
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime}