kaitai_struct_lua_runtime icon indicating copy to clipboard operation
kaitai_struct_lua_runtime copied to clipboard

Working with Lua 5.2

Open winstonwolfe06 opened this issue 7 years ago • 12 comments
trafficstars

Just wanted to note some challenges that I had while working with the runtime dependencies working with Lua 5.2 (which is what Wireshark comes with) vs Lua 5.3:

Bitwise operations needed to be modified to not use the standard symbols but instead utilize the bit32 supported ones: https://www.lua.org/manual/5.2/manual.html#6.7

Also string.unpack is not supported whereas Struct.unpack is and provides the same behavior.

All of these changes were made in the kaitaistruct.lua file.

winstonwolfe06 avatar Jul 09 '18 14:07 winstonwolfe06

Thanks! Do I get it correctly that it's possible to create a runtime which would work with both 5.2 and 5.3? If yes, could you prepare a pull request for these changes?

Bitwise operations needed to be modified to not use the standard symbols

I believe that it would be not affect the runtime, but also would require some changes in code generation as well?

Cc @adrianherrera

GreyCat avatar Jul 09 '18 14:07 GreyCat

Yeah, I think this will require changes to the translator as well (e.g. for bitwise operations).

adrianherrera avatar Jul 10 '18 04:07 adrianherrera

Note that the struct.unpack mentioned refers to http://www.inf.puc-rio.br/~roberto/struct/#unpack which was incorporated into Lua 5.3 as string.unpack.

Also the Lua 5.3 Reference Manual states:

Keep in mind that bit32 operates on 32-bit integers, while the bitwise operators in Lua 5.3 operate on Lua integers, which by default have 64 bits.

Lua 5.3 includes bit32 by default for compatibility but it will be removed completely in Lua 5.4.

cherue avatar Mar 12 '20 15:03 cherue

There are multiple syntax and module issues, Translator needs to be updated, but i want to ask, before I'll commit myself to the cause. I'm currently motivated, because of Wireshark integration I'd want to pursue, see https://github.com/smarek/Hytera_Homebrew_Bridge/issues/1 that @GreyCat @generalmimon there are two way, in my opinion, how to achieve Lua 5.2 support

  1. Update the translator and runtime to use iryont/lua-struct and BitOp, similar to what kaitai_struct_luajit_runtime already did
  2. Create Lua52Translator and kaitai_struct_lua52_runtime, that would do the same but separately, instead of forcing 5.3 users to use non-native bitop/struct (or maybe the lua version support level, could be just configuration option to kaitai-struct-compiler and only 5.2 runtime would be published separately?)

Could you please comment on, which of those ways you are more comfortable with?

smarek avatar Jul 30 '20 07:07 smarek

Why not make it 5.1 compatible, too? That would enable LuaJIT users, too.

Qix- avatar Aug 07 '20 05:08 Qix-

Shouldn't wireshark just upgrade the lua version?

KOLANICH avatar Aug 07 '20 05:08 KOLANICH

@KOLANICH Not as easy as it sounds. There are breaking API changes.

Qix- avatar Aug 07 '20 05:08 Qix-

@KOLANICH it might happen in Wireshark release 3, however when that will happen is unknown, and I'm not sure Wireshark devs have the motivation to do so. And as @Qix- said, could be 5.1 compatible even, however since Lua is not my standard knowledge, i'm not sure if 5.1 code is straight 5.2 compatible

smarek avatar Aug 07 '20 07:08 smarek

By the way, to be clear, yes you can write portable Lua. Just requires ponyfilling a few libs (e.g. bit vs bit32, table.unpack vs unpack, etc.)

Qix- avatar Aug 09 '20 05:08 Qix-

Great, so now the only thing remaining is the decision, do we want a separate translator for Lua and separate Lua 5.1+ compatible runtime, or do we want to update the current translator to directly produce Lua 5.1+ compatible code instead?

smarek avatar Aug 09 '20 17:08 smarek

Judging by previous experience, if we can afford doing cross-platform, and it's not terribly bad in terms of performance or having tons of ifs, it's much better user experience and simpler testing if we do cross-platform.

GreyCat avatar Aug 09 '20 17:08 GreyCat

So I think I've done it all, and this ticket can be closed in favor of #5

smarek avatar Aug 10 '20 15:08 smarek