You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When targetting Lua, the compiler currently writes all integer literals as decimal (unsurprisingly). When the value of a decimal integer doesn't fit into a signed 64-bit integer, Lua silently converts it to a float, losing precision. This causes problems with the way Kaitai Struct represents unsigned 64-bit integers in Lua (see #836) - such unsigned integers are actually represented as negative signed 64-bit integers to maintain precision. As a result, equality checks between unsigned 64-bit integers read from a file and ones written literally in a KSY currently fail. This problem can be seen in the integers test (generated Lua code):
The solution would be to write large unsigned 64-bit integers (that are outside of the signed 64-bit integer range) as hexadecimal literals instead. Unlike decimal literals, Lua doesn't automatically convert hexadecimal literals to float, and instead wraps/overflows them in the same way that Kaitai Struct does when reading. A similar solution was also implemented for Java, which also doesn't have unsigned 64-bit integers and uses a similar workaround (see #835): kaitai-io/kaitai_struct_compiler@dbda9b7
When targetting Lua, the compiler currently writes all integer literals as decimal (unsurprisingly). When the value of a decimal integer doesn't fit into a signed 64-bit integer, Lua silently converts it to a float, losing precision. This causes problems with the way Kaitai Struct represents unsigned 64-bit integers in Lua (see #836) - such unsigned integers are actually represented as negative signed 64-bit integers to maintain precision. As a result, equality checks between unsigned 64-bit integers read from a file and ones written literally in a KSY currently fail. This problem can be seen in the
integers
test (generated Lua code):The solution would be to write large unsigned 64-bit integers (that are outside of the signed 64-bit integer range) as hexadecimal literals instead. Unlike decimal literals, Lua doesn't automatically convert hexadecimal literals to float, and instead wraps/overflows them in the same way that Kaitai Struct does when reading. A similar solution was also implemented for Java, which also doesn't have unsigned 64-bit integers and uses a similar workaround (see #835): kaitai-io/kaitai_struct_compiler@dbda9b7
Originally reported in kaitai-io/kaitai_struct_lua_runtime#13.
The text was updated successfully, but these errors were encountered: