Using the first ts line will produce the following error after ~32K iterations:
process_message() attempt to call a nil value. The second line will work correctly.
Both are sub optimal because a temporary grammar is being constructed for every message. When the grammar is constructed outside of process_message everything works as expected and memory usage is stable (making this issue disturbing but low priority at the moment).
local l = require "lpeg"
l.locale(l)
local function time_to_ns(t)
return 1
end
local date_fullyear = l.Cg(l.digit * l.digit * l.digit * l.digit, "year")
function process_message()
local pl = read_message("Payload")
--local ts = lpeg.match(date_fullyear / time_to_ns, pl)
local ts = lpeg.match(l.Cg(l.digit * l.digit * l.digit * l.digit, "year") / time_to_ns, pl)
if not ts then return -1 end
return 0
end
Using the first ts line will produce the following error after ~32K iterations:
process_message() attempt to call a nil value
. The second line will work correctly. Both are sub optimal because a temporary grammar is being constructed for every message. When the grammar is constructed outside of process_message everything works as expected and memory usage is stable (making this issue disturbing but low priority at the moment).@whd