함수에 argument로 pass 될때는 call by reference 로 넘겨진다.
함수에서 return 되는 것도 당연히 포인터가 리턴됨.
function printTable(table)
print("------------")
if(table == nil) then
print("this table is nil!")
else
for k, v in pairs(table) do
print(k, v)
end
end
end
function getAnotherRefOfTable(table)
local anotherTableRef = table
anotherTableRef["job"] = "Magician"
return anotherTableRef
end
local a = {name="Kiki", job="Witch"}
local b = a -- Values are copied
printTable(a)
a = nil
printTable(a)
printTable(b)
local c = getAnotherRefOfTable(b) -- Called by reference
printTable(c)
No comments:
Post a Comment