lua-users home
lua-l archive

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



On 14/10/14 10:03 AM, Roberto Ierusalimschy wrote:
The idea is new semantics for __newindex so you can use it without rawset():

function __newindex(t,k,v)
   if condition then
     return k,nv
   elseif othercondition then
     return nk,v
   elseif anothercondition then
     return nk,nv
   else
     return k,v
   end
end
Would that be exactly equivalent to this?

   function __newindex(t,k,v)
     if condition then
       rawset(t,k,nv)
     elseif othercondition then
       rawset(t,nk,v)
     elseif anothercondition then
       rawset(t,nk,nv)
     else
       rawset(t,k,v)
     end
   end

What is the gain?

-- Roberto

the gain is that I don't have to expose rawset...