lua-users home
lua-l archive

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


>From: David Jeske <jeske@home.chat.net>
>
>I'm sorry, in all my examples I never once used the feature I wanted
>to have, because I didn't actually _do_ anything in any of the
>loops. Lets try again:
>
>function correlate_data(tbl1,tbl2)
>  local output_tbl = {};
>
>  for(1,2,macro(x)
>     output_tbl[x] = tbl2[tbl1[x]];
>  end);
>
>  return (output_tbl);
>end

this is where upvalues enter! check this out:

 function correlate_data(tbl1,tbl2)
   local output_tbl = {};

   for(1,2,function (x)			-- use the 'for' *function*
      %output_tbl[x] = %tbl2[%tbl1[x]];	-- see the upvalues!
   end);

   return (output_tbl);			-- no need for parentheses here
 end

this should work.
--lhf