lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Mon, May 8, 2017 at 3:02 PM, Ross Berteig <ross@cheshireeng.com> wrote:

The fact that tables are "stored by reference" is just an implementation detail that makes the value semantics of tables practical to implement. This is similar to strings being internalized, which is also just an implementation detail that make their value semantics practical to implement.


Lua tables do not have value semantics, as you examples are clearly showing.

a={}
b=a
a.x = 1
b.x = 2
print(a.x) -- prints 2

This is reference semantics. You'd see '1' if Lua implemented value semantics.

String internalization is a different beast, because strings are immutable, so value semantics and reference semantics are indistinguishable if you ignore memory and complexity issues.


--
--