Lua treats all number variables as floats. Forcing a cast to integer with math.floor
gave better results.
Modulo (%
) returns a non-integer if passed a non-integer so may need wrapped also.
Maybe better to rework the math logic if bit positions are the target?
1/31/2023 9:48:19 PM line = 290 : value1 = 1 value2 = 0 value3 = 0 value4 = 10
1/31/2023 9:48:19 PM line = 299 : value1 = 1 value2 = 0 value3 = 0 value4 = 10
1/31/2023 9:48:19 PM line = 307 : value1 = 1 value2 = 0 value3 = 0 value4 = 14
1/31/2023 9:48:19 PM line = 315 : value1 = 1 value2 = 0 value3 = 0 value4 = 14
2.1 โ Values and Types
There are eight basic types in Lua: nil, boolean, number, string, function, userdata, thread, and table.
Number represents real (double-precision floating-point) numbers.
cmdindex = 10
tox_flag = 65
tox_flag_reliablesn = math.floor(tox_flag/64)
tox_flag_reliablesn = tox_flag_reliablesn%2
tox_flag_frag = math.floor(tox_flag/128)
print("tox_flag_frag =", tox_flag_frag)
tox_flag_life = math.floor(tox_flag/32)
tox_flag_life = (tox_flag_life%2
3.4.1 โ Arithmetic Operators
Modulo is defined as
a % b == a - math.floor(a/b)*b
That is, it is the remainder of a division that rounds the quotient towards minus infinity.
20 โ The String Library
The function string.format is a powerful tool when formatting strings, ...
Changing the debug line from integer (%d
) to floats (%f
) :
local message = string.format("line = %f : value1 = %f value2 = %f value3 = %f value4 = %f", lineno, value1, value2, value3, value4)
shows that the variables are non-zero values.
2/1/2023 10:50:31 AM line = 290.000000 : value1 = 1.015625 value2 = 0.031250 value3 = 0.507813 value4 = 10.000000
2/1/2023 10:50:31 AM line = 299.000000 : value1 = 1.015625 value2 = 0.031250 value3 = 0.507813 value4 = 22.000000
2/1/2023 10:50:31 AM line = 307.000000 : value1 = 1.015625 value2 = 0.031250 value3 = 0.507813 value4 = 26.000000
2/1/2023 10:50:31 AM line = 315.000000 : value1 = 1.015625 value2 = 0.031250 value3 = 0.507813 value4 = 30.000000
Can you update the question with output of
wireshark -v
orHelp->About Wireshark:Wireshark
.Output below from
Tools->Lua->Evaluate
with version 4.0.3.My labtop is Mac,
next is output of Help->About Wireshark:Wireshark.
==============================================
Version 3.6.7 (v3.6.7-0-g4a304d7ec222) Copyright 1998-2022 Gerald Combs [email protected] and contributors. License GPLv2+: GNU GPL version 2 or later https://www.gnu.org/licenses/gpl-2.0.htmlThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiled (64-bit) using Clang 13.0.0 (clang-1300.0.29.30), with Qt 5.15.3, with libpcap, without POSIX capabilities, with GLib 2.68.4, with zlib 1.2.11, with Lua 5.2.4, with GnuTLS 3.6.15 and PKCS #11 support, with Gcrypt 1.8.7, with MIT Kerberos, with MaxMind DB resolver, with nghttp2 1.46.0, with brotli, with LZ4, with Zstandard, with Snappy, with libxml2 2.9.9, with libsmi 0.4.8, with QtMultimedia, with ...(more)
Is it possible the flags are not being reinitialized on successive passes through the code?
here is more code with flag variable initialization, and also I use debug_func to dump flag variable and cmdindex,
the flag variable is expected as next :
tox_flag_frag = 0
tox_flag_reliablesn = 1
tox_flag_life = 0
but the cmdindex is 22 when debug_func(299, tox_flag_reliablesn, tox_flag_life, tox_flag_frag, cmdindex), this is unexpected...
Don't understand why this happen...
================================================
(more)What is the value of
curindex
and what is the value oftox_flag
after this call:The
tvb()
offset field is 0-based, so perhaps you're off by 1? From https://www.wireshark.org/docs/wsdg_h...: