lua-users home
lua-l archive

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




Le jeu. 29 nov. 2018 à 15:22, Philippe Verdy <verdy_p@wanadoo.fr> a écrit :
Le mer. 28 nov. 2018 à 11:06, Egor Skriptunoff <egor.skriptunoff@gmail.com> a écrit :
But the next question from Sony L. would be the following:
How to save intermediate value in this code
a:b.c()
a:b.d()

This idea a very strange object type in Lua creating an object that references two:
 
to rewrite it in optimized way
local x = a:b
x.c()
x.d()

The way I percieve it is that "x" should be a "proxying" function object (which internally will call function "b"), defined in a closure that holds the value "a". Something like:

Fix:

local x = function(a, b)
  local __o___ = a;
  return function(...)
    return b(__o__, ...)
  end
end
x(c)
x(d)

Sorry: I forgot the (a,b) parameters to the first function...