LUA表的引用理解

--lua中引用类型都是分配在堆上的
--因此,我们在使用LUA的table时,可尽可能的使用表的引用,而不需要拷贝表里的元素
--比如,通过RPC协议传来一个表A,我们想要缓存这个表,只需要保存该表的引用
--而不需要再重新生成一个新表然后将表A的元素一个个拷过来
function func()
    local t = {x = 10, y=20} --生成一个表,是堆上的,并非栈上的,t是栈上的
    local hello = "hello"
    local num = 111
    return t, hello, num
end

t, str, num = func()
print(t.x, t.y, str, num)
原文地址:https://www.cnblogs.com/timeObjserver/p/6295684.html