lua-users home
lua-l archive

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


Thanks and sorry for this silly question,.
__newindex function behaves the same as any function, of course.

----- Original Message ----- From: "Duncan Cross" <duncan.cross@gmail.com>
To: "Lua mailing list" <lua-l@lists.lua.org>
Sent: Friday, June 30, 2017 11:11 AM
Subject: Re: __newindex setting table


On Fri, Jun 30, 2017 at 9:50 AM, Victor Bombi <sonoro@telefonica.net> wrote:
Hi,

Where in the docs can be infered that

local aa = metatable({},{__newindex = function(t,i,v) t=v end})

aa[0] = 24

is not performing aa = 24

Best
victor bobi


2.1 - Values and Types

"Tables, functions, threads, and (full) userdata values are objects:
variables do not actually contain these values, only references to
them. Assignment, parameter passing, and function returns always
manipulate references to such values; these operations do not imply
any kind of copy."


So, in your case, the parameter "t" and the variable "aa" are seperate
references, -- reassigning one reference does not affect the other.


-Duncan