Two Things

Gaming and Programming.. maybe programming for some games, who knows. Either way, I'm a geek, right?

LUA Uses References. Who Knew?

Well probably a lot of people knew.  I've started messing around in WildStar's addon universe, which is based in LUA.  I haven't touched LUA since the original release of World of Warcraft when I wrote a crowd-control addon to keep track of my warlock's mesmerizing targets.  So WildStar uses LUA as well.

I had made an assumption since LUA is a scripting language that it was not very object-oriented and things like values and references weren't really relevant.

Take this bit of code:

local TableOne = {}
TableOne.Fruit = "Apple"
local TableTwo = TableOne
TableTwo.Fruit = "Banana"
Print(TableOne.Fruit)

As a regular scripting language I expected "Apple" since I thought line 3 made an independent copy of the table.  I was wrong though, it's a reference pointer, and the printout will be "Banana."

If you want to have a copy of a table that is separate from the original you have to write a function that does a shallow or deep copy as you need it in your specific script.  LUA doesn't have an innate table copy function because there are apparently several nuances that you have to be aware of.