lua-users home
lua-l archive

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


On 9/1/05, Rici Lake <lua@ricilake.net> wrote:
> On 1-Sep-05, at 8:18 AM, Lisa Parratt wrote:
> > Boyko Bantchev wrote:
> >> ... assuming `simple' values are meant.  Because tables, e.g.,
> >> _are_ passed by reference.
> 
> They might look like they're being passed by reference, but they're
> not. All arguments in Lua are passed by value. They are not passed by
> copy, so when you pass a table (by value) you are passed the same
> table, which means you can mutate it (arg[key] = 42) or compare its
> object identity with another table, etc. Immutable objects (such as
> numbers and strings) are not copied either, since there are no
> mutators, so the copy is unnecessary.

Thanks for clarifying this.  My mistake.
I did not, and still do not have any idea how passing tables
as arguments is implemented, but at least for simple uses
the result is indistinguishable from passing by reference.
Actually, my point was simply to prevent the asker of the
original question (or anyone else) from thinking that tables
are being copied (e.g., like Pascal var arrays are).

   B.