summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xepan/wslua/make-taps.pl6
-rw-r--r--epan/wslua/wslua_nstime.c12
-rw-r--r--test/lua/nstime.lua11
3 files changed, 22 insertions, 7 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 }
};
diff --git a/test/lua/nstime.lua b/test/lua/nstime.lua
index 65d1b60e93..c8ecdd2d29 100644
--- a/test/lua/nstime.lua
+++ b/test/lua/nstime.lua
@@ -31,7 +31,7 @@ end
-- note ip only runs 3 times because it gets removed
-- and bootp only runs twice because the filter makes it run
-- once and then it gets replaced with a different one for the second time
-local taptests = { [FRAME]=4, [OTHER]=37 }
+local taptests = { [FRAME]=4, [OTHER]=40 }
local function getResults()
print("\n-----------------------------\n")
for k,v in pairs(taptests) do
@@ -132,13 +132,16 @@ test("NSTime.tostring-32", tostring(first) == "0.000000000")
test("NSTime.tostring-33", tostring(second) == "100.000000100")
test("NSTime.tostring-34", tostring(third) == "0.000000100")
+test("NSTime.tonumber-35", first:tonumber() == 0.0)
+test("NSTime.tonumber-36", second:tonumber() == 100.0000001)
+test("NSTime.tonumber-37", third:tonumber() == 0.0000001)
testing(OTHER,"setters/getters")
first.secs = 123
first.nsecs = 100
-test("NSTime.set-35", first == NSTime(123,100))
-test("NSTime.get-36", first.secs == 123)
-test("NSTime.get-37", first.nsecs == 100)
+test("NSTime.set-38", first == NSTime(123,100))
+test("NSTime.get-39", first.secs == 123)
+test("NSTime.get-40", first.nsecs == 100)
----------------------------------