I'm a bit confused with how Lua treats object references in function arguments. Consider this example:
local tableA = {name = "A"}
local tableB = {name = "B"}
local tableC = {name = "C"}
local function childA(a, b)
a = tableC
b.name = "This works"
end
local function childB(a, b)
print("a =", a.name) -- expected to print "C"
print("b =", b.name) -- prints "This works" as expected
end
local function parentFunction(a, b)
childA(a, b)
childB(a, b)
end
parentFunction(tableA, tableB)
I would expect that in the childA function the a parameter will be replaced by reference to tableC that will continue to be tableC from now on, but it does not happen. Whereas if I change just a property of such parameter in the b parameter it will affect reads of the object down the line. Why the overwrite is not working like this?