July 2018
Beginner
202 pages
5h 42m
English
The last thing to know about tables before moving on to the next section is that they are stored by reference, not value! This is very important: integers and other primitive types are assigned by value, tables are assigned by reference. What does this mean?
If you assign one variable to another variable by value, each variable has its own copy. This means you can edit both variables independently. Here is an example:
x = 10 -- y assigned 10 by valuey = x -- y assigned the value of x (10) by valuex = 15 -- x assigned 15 by valueprint (x) -- 15print (y) -- 10
When you assigned a variable by reference, however, multiple variables might hold the same reference. If you assign the same reference to multiple variables, ...