summaryrefslogtreecommitdiff
path: root/epan
diff options
context:
space:
mode:
authorSilvio Gissi <silvio.gissi@gmail.com>2017-06-21 15:46:45 -0400
committerGuy Harris <guy@alum.mit.edu>2017-06-21 23:50:27 +0000
commit59add43eecfbed3bae5d75dabe6e875b5adefe1b (patch)
tree34091c5a565ea91e02b2f83a3423b3a8aa7a2082 /epan
parent16f70b9bb1faf48d985e21fcfa92d1934c2b50f5 (diff)
downloadwireshark-59add43eecfbed3bae5d75dabe6e875b5adefe1b.tar.gz
Lua: Add "tonumber" method to NSTime
Absolute and Relative time fields could not be converted to seconds without converting to string and parsing to number. Fixed conversion in generated code that was subject to precision loss Usage: f=Field.new("frame.delta_time") delta=f().value:tonumber() Change-Id: I6ef91c6238a6c2ed9adf6cae03f8913f0a09332e Reviewed-on: https://code.wireshark.org/review/22316 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan')
-rwxr-xr-xepan/wslua/make-taps.pl6
-rw-r--r--epan/wslua/wslua_nstime.c12
2 files changed, 15 insertions, 3 deletions
diff --git a/epan/wslua/make-taps.pl b/epan/wslua/make-taps.pl
index e2d6bd2c91..ef41ba8937 100755
--- a/epan/wslua/make-taps.pl
+++ b/epan/wslua/make-taps.pl
@@ -43,8 +43,8 @@ my %types = %{{
'address' => '{ Address a = (Address)g_malloc(sizeof(address)); copy_address(a, &(v->STR)); pushAddress(L,a); }',
'address*' => '{ Address a = (Address)g_malloc(sizeof(address)); copy_address(a, v->STR); pushAddress(L,a); }',
'int' => 'lua_pushnumber(L,(lua_Number)v->STR);',
- 'nstime_t' => '{ lua_Number t = (lua_Number) v->STR.secs; t += v->STR.nsecs * 1e-9; lua_pushnumber(L,t); }',
- 'nstime_t*' => '{ lua_Number t = (lua_Number) v->STR->secs; t += v->STR->nsecs * 1e-9; lua_pushnumber(L,t); }',
+ 'nstime_t' => 'lua_pushnumber(L,(lua_Number)nstime_to_sec(&(v->STR)));',
+ 'nstime_t*' => 'lua_pushnumber(L,(lua_Number)nstime_to_sec(v->STR));'
}};
my %comments = %{{
@@ -164,6 +164,8 @@ print CFILE <<"HEADER";
#include "wslua.h"
+#include <wsutil/nstime.h>
+
HEADER
print DOCFILE "\n";
diff --git a/epan/wslua/wslua_nstime.c b/epan/wslua/wslua_nstime.c
index e04524151d..f0a87f0595 100644
--- a/epan/wslua/wslua_nstime.c
+++ b/epan/wslua/wslua_nstime.c
@@ -30,7 +30,7 @@
#include "config.h"
#include "wslua.h"
-
+#include <wsutil/nstime.h>
/* WSLUA_CONTINUE_MODULE Pinfo */
@@ -61,6 +61,15 @@ WSLUA_METAMETHOD NSTime__call(lua_State* L) { /* Creates a NSTime object. */
WSLUA_RETURN(NSTime_new(L)); /* The new NSTime object. */
}
+WSLUA_METHOD NSTime_tonumber(lua_State* L) {
+ /* Returns a Lua number of the `NSTime` representing seconds from epoch
+ * @since 2.4.0
+ * */
+ NSTime nstime = checkNSTime(L,1);
+ lua_pushnumber(L, (lua_Number)nstime_to_sec(nstime));
+ WSLUA_RETURN(1); /* The Lua number. */
+}
+
WSLUA_METAMETHOD NSTime__tostring(lua_State* L) {
NSTime nstime = checkNSTime(L,1);
gchar *str;
@@ -174,6 +183,7 @@ WSLUA_ATTRIBUTES NSTime_attributes[] = {
WSLUA_METHODS NSTime_methods[] = {
WSLUA_CLASS_FNREG(NSTime,new),
+ WSLUA_CLASS_FNREG(NSTime,tonumber),
{ NULL, NULL }
};