The documentation describes how to access the packet timestamps using Is there a way of getting a more precise timestamp for the packet, ideally with nanosecond precision, from Lua? asked 17 Mar '14, 11:36 randomphrase |
One Answer:
I haven't tried it, but what it should be doing is returning a Lua number with the fractional part representing the nanoseconds. So if the absolute time is 123456 seconds and 789 nanoseconds, when you get A Lua number is a double, so it has a fractional component, and answered 17 Mar '14, 11:53 Hadriel edited 17 Mar '14, 11:54 |
Ah yes of course - don't know why I missed something so obvious.
For future reference, here's what worked for me:
(Possibly could be made more elegant by someone more knowledgable about Lua than I!)
There's no reason to do a
math.modf()
in the second argument toNSTime()
.NSTime()
will ignore any fractional component in its arguments.Really what you're doing there anyway is giving
NSTime()
three arguments: (1) thesecs
, (2) the integral number offrac * 10^9
, and (3) the fractional number offrac * 10^9
. LuckilyNSTime()
ignores this third argument you're passing, but this might break someday ifNSTime()
is enhanced to take a third optional argument for something.You could also do this instead, though I think your way is clearer and easier to read:
But maybe what we really need is for
pinfo
to provide a way to get the NSTime object as a return value for abs_ts (and the other times). So you don't have to do this shenanigans. :)