lua-users home
lua-l archive

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

On Wed, Feb 16, 2011 at 3:15 PM, Alex Bradbury <> wrote:
> You said you were playing with templating Francesco's code. Do share
> if you find any particularly helpful tricks.

One pattern works like this:

   -- k3 step
   $(VL'k_') = f(t + 0.5 + h,$(VL'ytmp_'))

expands to
    k_0,k_1 = f(t + 0.5 + h,ytmp_0,ytmp_1)

the definition of VL is easy:

# function VL(var)
#  local res = {}
#  for i = N1,N2 do
#    res[i+1-N1] = var..i
#  end
#  return table.concat(res,',')
# end

Another common one is:

   $(AL 's.y') = $(VL 'v_')


   s.y[0],s.y[1] = v_0,v_1

About as pretty as it can get, although a little meta magic can make
$(V.v) behave like $(VL 'v_')

That is while still keeping to the original, very simple preprocessor.
 A macro expansion facility on top of that can eliminate some dollars
but the interactions could get hairy...

>, though
> providing a preprocess function that takes an environment argument.

Yes, that's the way to go...  Still thinking about how to organize
template 'instantiation' since a template function may depend on
several other template functions.

steve d.