lua-users home
lua-l archive

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


Am 08.05.2014 20:11 schröbte Pierre-Yves Gérardy:
On Thu, May 8, 2014 at 5:35 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 08.05.2014 17:24 schröbte Pierre-Yves Gérardy:
L="local a,b,c=..."load(L.."")load(L.."")
function(a,b,c)endfunction(a,b)end


Yes, and we also rely on upvalues, so we would need the `function` keyword
in there after all ...
But for a moment it was a good idea.

No need for upvalues, a Lua chunck really is a vararg function:

     add = load"local a,b = ... return a + b"
     add(1,2) --> 3

If you want to use the `type` (or `next`) function in there without passing it in every call, then you need them as upvalues. E.g.:

    add = load[[
      local t = ...
      return function( a, b )
        if t( a ) == t( b ) then
          return a + b
        end
      end]]( type )

Personally, I usually don't localize all globals in toy programs, but the OP seems to care. Better safe than sorry, I guess.


—Pierre-Yves


Philipp