lua-users home
lua-l archive

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


I tried to use lpeg.Cf with a non-numeric accumulator (in 
lpeg 0.12) thus:

  #!lua
  local digit = lpeg.R "09"
  local num = lpeg.C(digit^1)/tonumber
  local comma = lpeg.C ","
  local acc = function (t,x,y)
                t[1] = t[1] + x
                t[2] = t[2] + y
              end
  local vec = lpeg.Cf (num * comma * num, acc)
  local pat = lpeg.Cc { 0, 0} * (vec + 1)^0
  local t = pat:match "Try (3,4) plus (100,200)"
  print ("(", t[1], ",", t[2], ")")

but it spat it out with "attempt to index local 't' (a number value)".
Are there good reasons why lpeg.Cf only works with number values?

You can probably see what I am trying to do. Is the problem my 
poor coding or the type restriction on lpeg.Cf? 
Is the restriction necessary?

-- 
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/