From 0af0e8a58d5d8b5e373e0e8068f6c95fd8166312 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 27 Dec 2024 09:25:09 +0300 Subject: [PATCH] update byteutil --- src/logic/scripting/lua/libs/libbyteutil.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/logic/scripting/lua/libs/libbyteutil.cpp b/src/logic/scripting/lua/libs/libbyteutil.cpp index e4b20d8c..c221ad25 100644 --- a/src/logic/scripting/lua/libs/libbyteutil.cpp +++ b/src/logic/scripting/lua/libs/libbyteutil.cpp @@ -11,6 +11,7 @@ static size_t calc_size(const char* format) { switch (format[i]) { case 'b': case 'B': + case '?': outSize += 1; break; case 'h': @@ -43,8 +44,14 @@ static int pack(lua::State* L, const char* format, bool usetable) { for (int i = 0; format[i]; i++) { switch (format[i]) { case 'b': + builder.put(lua::tointeger(L, index)); + break; + case 'B': builder.put(lua::tointeger(L, index) & 0xFF); break; + case '?': + builder.put(lua::toboolean(L, index) ? 1 : 0); + break; case 'h': builder.putInt16(lua::tointeger(L, index), bigEndian); break; @@ -102,6 +109,7 @@ static int count_elements(const char* format) { switch (format[i]) { case 'b': case 'B': + case '?': case 'h': case 'H': case 'i': @@ -133,6 +141,12 @@ static int l_unpack(lua::State* L) { case 'b': lua::pushinteger(L, reader.get()); break; + case 'B': + lua::pushinteger(L, reader.get() & 0xFF); + break; + case '?': + lua::pushboolean(L, reader.get() != 0); + break; case 'h': lua::pushinteger(L, reader.getInt16(bigEndian)); break;