lua-users home
lua-l archive

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

On Mon, Sep 14, 2009 at 8:45 PM, David Manura wrote:
> we would need to make [2] like [3] but not introduce a new stack level.
> Currently, Lua lacks a documented way to express that type of currying
> operation.

Related to this, sometimes I'd like to be able to call a function
without increasing the stack level.  For example, let f be a function
that internally deals with stack levels:

  function f() error("opps", 2) end  -- or setfenv, debug.getinfo, etc.

Now say I want to wrap f inside another function:

  -- a function decorator that adds trace statements.
  function trace(f)
    return function(...)
      print('starting', f)
      print('stopping', f)

  f = trace(f)

This is not possible to do correctly because the wrapper increases the
stack level.  Maybe some special "call" function (in the form of
pcall) could be implemented to call a given function within the
current stack level.