lua-users home
lua-l archive

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



On Aug 14, 2009, at 12:00 AM, David Manura wrote:

One of the prototypical problems in [1] was to implement a function this:

 --Wraps a function with trace statements.
 function trace(f)
   return function(...)
     print("begin", f)
     local result = tuple(f(...))
     print("end", f)
     return result()
   end
 end

Could we add new keywords that correspond with the TUPLE/DETUPLE
opcodes to achieve something like the above?

[1] http://lua-users.org/wiki/VarargTheSecondClassCitizen


Would this work?

function trace (f)
  return function(...)
    print("begin", f)
    local function vals(...)
      print("end", f)
      return(...)
    end
    vals(f(...)...)
  end
end

e