lua-users home
lua-l archive

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


John Belmonte wrote:
>
>     function X(...)
> 
>         pre_function()
>         local results = compress(call(%X, arg))
>         post_function()
>         return expand(results)
>     end
> 
> If this all seems esoteric, here is a practical example.
>[...]

I've an idea for that still on my todo list.  Your may remember
a post be me where I talked about the "name[]" syntax?  At the
moment it's only used to name varargs.  But I wanted to make
it more general like this:

   local a,b,c[] = foo()

First result of foo to a, second to b, remaining packed into c.
Here the [] is a pack operator.

  foo(a,b,c[])

And here [] is the unpack operator.  So your example would become

  function X(args[])			-- pack args
    -- pre actions
    local results[] = %X(args[])	-- unpack args, pack results
    -- post actions
    return results[]			-- unpack results
  end

IMHO these two operations (pack/unpack) are fundamental.  You could
just make functions for them.  But having them as operators allows
us to later optimize them by the compiler (i.e. if args and results
is never accessed except via the pack/unpack operator you may just
move them somewhere on the stack without actually creating tables.
A _big_ optimization!).  And I can't see real problems in implementing
them.  (It's even compatible to old code *g*)

Ciao, ET.


PS: IMHO call() should be used to catch errors and not to unpack
arguments.  That's just a side effect on its calling convention.
More about this in a different post.