lua中的引用与拷贝

Lua中的基本类型是值传递,只有表是引用传递

-----------------例子一
x = 1  
y = x  
y = 10  
print(x)  
--输出:1  

-----------------例子二
function change(x)  
  x = 10  
end  
y = 1  
change(y)  
print(y)   
--输出:1  

-----------------例子三
x = "test"  
y = x  
x = "show"  
print(y)  
--输出:test  


-----------------例子四
x = {abc = "123",456}  
y = x  
x.abc = "xixi"  
print(y.abc)  
--输出:xixi  


-----------------例子五
function show()  
  print("show some thing")  
end   
function move()  
  print("move to")  
end  
x = show  
y = x  
x = move  
y()  
x()  
--输出:show some thing  
--      move to  


-----------------例子六
x = {123,"test"}  
y = x[1]  
x[1] = 456  
print(y)   
--输出:123  

你可能感兴趣的:(lua,深拷贝,引用)