[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Arguments by reference?
- From: Rici Lake <lua@...>
- Date: Thu, 1 Sep 2005 13:06:39 -0500
On 1-Sep-05, at 12:48 PM, Brent Arias wrote:
Not passed by reference? And not passed by copy either? I don't get
Those are the only two options. If its not a reference/pointer, and
a copy of the value...then...what?
If you don't think of variables and instead think of values, it is
Consider the primitive value 3. If (in C), I do:
Would you say that the 3 is being "copied"? Or that somefunc just gets
the value 3?
Now, in C++, if I call:
(i.e. not a reference or pointer, but someobj itself)
someobj is definitely copied, in the sense that the copy constructor is
Lua doesn't do that, which is why I said that it is not passed by copy.
So in Lua:
both do exactly the same thing: somefunc is passed the value, which is
3 or someobj, respectively. It cannot mutate 3, so the difference is
ignorable, but it may be able to mutate someobj (if someobj were a
mutable object), and if it does, it is mutating the same value as was
passed to it.