[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- 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
it.
Those are the only two options. If its not a reference/pointer, and
its not
a copy of the value...then...what?
If you don't think of variables and instead think of values, it is
simpler :)
Consider the primitive value 3. If (in C), I do:
somefunc(3);
Would you say that the 3 is being "copied"? Or that somefunc just gets
the value 3?
Now, in C++, if I call:
somefunc(someobj);
(i.e. not a reference or pointer, but someobj itself)
someobj is definitely copied, in the sense that the copy constructor is
invoked.
Lua doesn't do that, which is why I said that it is not passed by copy.
So in Lua:
somefunc(3)
somefunc(someobj)
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.