lua-users home
lua-l archive

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


On Tue, Dec 22, 2009 at 5:01 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
> BTW, does any one know more strict/formal definition for the way Lua
> values and variables are bound together (including assignment and
> function argument / return value passing)?

Very similar to Java, which is classically called pass by value for
primitives (numbers) and pass by reference for objects (tables).  The
pass by reference bit is a misnomer though, it's really "references
passed by value" but that's a mouthful.

In C terms, Lua variables behave exactly like normal ints and pointers
do.  A variable either holds a value, like 1, 4, or 77, or a pointer
to a table.  If two pointers point to the same table, changes made via
one pointer are reflected when accessed via the other.

I guess the key point is that although we generally talk of a variable
as being a table, it's really a pointer/reference to a table.