lua-users home
lua-l archive

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

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:


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 invoked.

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.