diff options
Diffstat (limited to 'epan/wslua/wslua_int64.c')
-rw-r--r-- | epan/wslua/wslua_int64.c | 442 |
1 files changed, 177 insertions, 265 deletions
diff --git a/epan/wslua/wslua_int64.c b/epan/wslua/wslua_int64.c index 17c00f06..b7b7d3c8 100644 --- a/epan/wslua/wslua_int64.c +++ b/epan/wslua/wslua_int64.c @@ -25,7 +25,7 @@ either expressed or implied, of the FreeBSD Project. /* WSLUA_MODULE Int64 Handling 64-bit Integers - Lua uses one single number representation which can be chosen at compile time and since it is often set to IEEE 754 double precision floating point, one cannot store 64 bit integers with full precision. + Lua uses one single number representation, which is chosen at compile time, and since it is often set to IEEE 754 double precision floating point, one cannot store 64 bit integers with full precision. Lua numbers are stored as floating point (doubles) internally, not integers; thus while they can represent incredibly large numbers, above 2^53 they lose integral precision -- they can't represent every whole integer value. For example if you set a lua variable to the number 9007199254740992 and tried to increment it by 1, you'd get the same number because it can't represent 9007199254740993 (only the even number 9007199254740994). @@ -39,9 +39,6 @@ either expressed or implied, of the FreeBSD Project. Note that comparison operators ('==','$$<=$$','>', etc.) will not work with plain numbers -- only other Int64/UInt64 objects. This is a limitation of Lua itself, in terms of how it handles operator overloading. - // Previous to Wireshark release 1.11, Int64 and UInt64 could only be created by tvbrange:int64() or tvbrange:le_int64(), or tvbrange:uint64() or tvbrange:le_uint64() or tvbrange:bitfield(), and had only a couple functions (the metamethods tostring() and concat()). - // All of the functions on this page are only available starting in Wireshark 1.11 and higher. - [WARNING] ==== Many of the UInt64/Int64 functions accept a Lua number as an argument. @@ -78,14 +75,24 @@ either expressed or implied, of the FreeBSD Project. -- Bad. Leads to inconsistent results across platforms local masked = mynum:band(0xFFFFFFFF00000000) ---- + + [NOTE] + ==== + Lua 5.3 and later adds a second number representation for integers, which is also chosen at compile time. It is usually a 64-bit signed integer type, even on 32-bit platforms. + (Lua 5.2 and earlier have an integer type, but this is not used for storing numbers, only for casting, and on 32-bit platforms is 32-bits wide.) + Wireshark 4.4 and later will use the Lua integer type where possible, but as storing + 64-bit unsigned integers in a Lua Integer can result in signed number overflow, `UInt64` + is still necessary. `Int64` is also still available for use. + ==== + */ #define LUATYPE64_STRING_SIZE 21 /* string to hold 18446744073709551615 */ #if G_BYTE_ORDER == G_LITTLE_ENDIAN -#define IS_LITTLE_ENDIAN TRUE +#define IS_LITTLE_ENDIAN true #else -#define IS_LITTLE_ENDIAN FALSE +#define IS_LITTLE_ENDIAN false #endif WSLUA_CLASS_DEFINE_BASE(Int64,NOP,0); @@ -95,15 +102,15 @@ WSLUA_CLASS_DEFINE_BASE(Int64,NOP,0); Note the caveats <<lua_module_Int64,listed above>>. */ -/* A checkInt64 but that also auto-converts numbers, strings, and UINT64 to a gint64 */ -static gint64 getInt64(lua_State *L, int i) +/* A checkInt64 but that also auto-converts numbers, strings, and UINT64 to a int64_t */ +static int64_t getInt64(lua_State *L, int i) { - gchar *end = NULL; + char *end = NULL; (void) end; switch (lua_type(L,i)) { case LUA_TNUMBER: - return wslua_checkgint64(L,i); + return wslua_checkint64(L,i); case LUA_TSTRING: return g_ascii_strtoll(luaL_checkstring(L,i),&end,10); case LUA_TUSERDATA: @@ -118,36 +125,34 @@ static gint64 getInt64(lua_State *L, int i) /* Encodes Int64 userdata into Lua string struct with given endianness */ -void Int64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittleEndian) { - gint64 value = checkInt64(L,idx); - gint8 buff[sizeof(gint64)]; +void Int64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian) { + int64_t value = checkInt64(L,idx); + int8_t buff[sizeof(int64_t)]; if (asLittleEndian) { - guint i; - for (i = 0; i < sizeof(gint64); i++) { + unsigned i; + for (i = 0; i < sizeof(int64_t); i++) { buff[i] = (value & 0xff); value >>= 8; } } else { - gint i; - for (i = sizeof(gint64) - 1; i >= 0; i--) { + int i; + for (i = sizeof(int64_t) - 1; i >= 0; i--) { buff[i] = (value & 0xff); value >>= 8; } } - luaL_addlstring(b, (char*)buff, sizeof(gint64)); + luaL_addlstring(b, (char*)buff, sizeof(int64_t)); } WSLUA_METHOD Int64_encode(lua_State* L) { - /* Encodes the <<lua_class_Int64,`Int64`>> number into an 8-byte Lua string using the given endianness. - @since 1.11.3 - */ + /* Encodes the <<lua_class_Int64,`Int64`>> number into an 8-byte Lua string using the given endianness. */ #define WSLUA_OPTARG_Int64_encode_ENDIAN 2 /* If set to true then little-endian is used, if false then big-endian; if missing or `nil`, native host endian. */ luaL_Buffer b; - gboolean asLittleEndian = IS_LITTLE_ENDIAN; + bool asLittleEndian = IS_LITTLE_ENDIAN; if (lua_gettop(L) >= WSLUA_OPTARG_Int64_encode_ENDIAN) { if (lua_type(L,WSLUA_OPTARG_Int64_encode_ENDIAN) == LUA_TBOOLEAN) @@ -163,20 +168,20 @@ WSLUA_METHOD Int64_encode(lua_State* L) { } /* Decodes from string buffer struct into Int64 userdata, with given endianness */ -int Int64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian) { - gint64 value = 0; - gint i; +int Int64_unpack(lua_State* L, const char *buff, bool asLittleEndian) { + int64_t value = 0; + int i; if (asLittleEndian) { - for (i = sizeof(gint64) - 1; i >= 0; i--) { + for (i = sizeof(int64_t) - 1; i >= 0; i--) { value <<= 8; - value |= (gint64)(guchar)buff[i]; + value |= (int64_t)(unsigned char)buff[i]; } } else { - for (i = 0; i < (gint) sizeof(gint64); i++) { + for (i = 0; i < (int) sizeof(int64_t); i++) { value <<= 8; - value |= (gint64)(guchar)buff[i]; + value |= (int64_t)(unsigned char)buff[i]; } } @@ -185,23 +190,21 @@ int Int64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian) { } WSLUA_CONSTRUCTOR Int64_decode(lua_State* L) { - /* Decodes an 8-byte Lua string, using the given endianness, into a new <<lua_class_Int64,`Int64`>> object. - @since 1.11.3 - */ + /* Decodes an 8-byte Lua string, using the given endianness, into a new <<lua_class_Int64,`Int64`>> object. */ #define WSLUA_ARG_Int64_decode_STRING 1 /* The Lua string containing a binary 64-bit integer. */ #define WSLUA_OPTARG_Int64_decode_ENDIAN 2 /* If set to true then little-endian is used, if false then big-endian; if missing or `nil`, native host endian. */ - gboolean asLittleEndian = IS_LITTLE_ENDIAN; + bool asLittleEndian = IS_LITTLE_ENDIAN; size_t len = 0; - const gchar *s = luaL_checklstring(L, WSLUA_ARG_Int64_decode_STRING, &len); + const char *s = luaL_checklstring(L, WSLUA_ARG_Int64_decode_STRING, &len); if (lua_gettop(L) >= WSLUA_OPTARG_Int64_decode_ENDIAN) { if (lua_type(L,WSLUA_OPTARG_Int64_decode_ENDIAN) == LUA_TBOOLEAN) asLittleEndian = lua_toboolean(L,WSLUA_OPTARG_Int64_decode_ENDIAN); } - if (len == sizeof(gint64)) { + if (len == sizeof(int64_t)) { Int64_unpack(L, s, asLittleEndian); } else { lua_pushnil(L); @@ -211,26 +214,24 @@ WSLUA_CONSTRUCTOR Int64_decode(lua_State* L) { } WSLUA_CONSTRUCTOR Int64_new(lua_State* L) { - /* Creates a <<lua_class_Int64,`Int64`>> Object. - @since 1.11.3 - */ + /* Creates a <<lua_class_Int64,`Int64`>> object. */ #define WSLUA_OPTARG_Int64_new_VALUE 1 /* A number, <<lua_class_UInt64,`UInt64`>>, <<lua_class_Int64,`Int64`>>, or string of ASCII digits to assign the value of the new <<lua_class_Int64,`Int64`>>. Default is 0. */ #define WSLUA_OPTARG_Int64_new_HIGHVALUE 2 /* If this is a number and the first argument was a number, then the first will be treated as a lower 32 bits, and this is the high-order 32 bit number. */ - gint64 value = 0; + int64_t value = 0; if (lua_gettop(L) >= 1) { switch(lua_type(L, WSLUA_OPTARG_Int64_new_VALUE)) { case LUA_TNUMBER: - value = wslua_togint64(L, WSLUA_OPTARG_Int64_new_VALUE); + value = wslua_toint64(L, WSLUA_OPTARG_Int64_new_VALUE); if (lua_gettop(L) == 2 && lua_type(L, WSLUA_OPTARG_Int64_new_HIGHVALUE) == LUA_TNUMBER) { - gint64 h = wslua_togint64(L, WSLUA_OPTARG_Int64_new_HIGHVALUE); - value &= G_GUINT64_CONSTANT(0x00000000FFFFFFFF); - h <<= 32; h &= G_GUINT64_CONSTANT(0xFFFFFFFF00000000); + int64_t h = wslua_toint64(L, WSLUA_OPTARG_Int64_new_HIGHVALUE); + value &= UINT64_C(0x00000000FFFFFFFF); + h <<= 32; h &= UINT64_C(0xFFFFFFFF00000000); value += h; } break; @@ -250,66 +251,54 @@ WSLUA_CONSTRUCTOR Int64_new(lua_State* L) { } WSLUA_METAMETHOD Int64__call(lua_State* L) { - /* Creates a <<lua_class_Int64,`Int64`>> object. - @since 1.11.3 - */ + /* Creates a <<lua_class_Int64,`Int64`>> object. */ lua_remove(L,1); /* remove the table */ WSLUA_RETURN(Int64_new(L)); /* The new <<lua_class_Int64,`Int64`>> object. */ } WSLUA_CONSTRUCTOR Int64_max(lua_State* L) { - /* Creates an <<lua_class_Int64,`Int64`>> of the maximum possible positive value. In other words, this should return an Int64 object of the number 9,223,372,036,854,775,807. - @since 1.11.3 - */ - pushInt64(L, G_MAXINT64); + /* Creates an <<lua_class_Int64,`Int64`>> of the maximum possible positive value. In other words, this should return an Int64 object of the number 9,223,372,036,854,775,807. */ + pushInt64(L, INT64_MAX); WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>> object of the maximum value. */ } WSLUA_CONSTRUCTOR Int64_min(lua_State* L) { - /* Creates an <<lua_class_Int64,`Int64`>> of the minimum possible negative value. In other words, this should return an Int64 object of the number -9,223,372,036,854,775,808. - @since 1.11.3 - */ - pushInt64(L, G_MININT64); + /* Creates an <<lua_class_Int64,`Int64`>> of the minimum possible negative value. In other words, this should return an Int64 object of the number -9,223,372,036,854,775,808. */ + pushInt64(L, INT64_MIN); WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>> object of the minimum value. */ } WSLUA_METHOD Int64_tonumber(lua_State* L) { - /* Returns a Lua number of the <<lua_class_Int64,`Int64`>> value. Note that this may lose precision. - @since 1.11.3 - */ + /* Returns a Lua number of the <<lua_class_Int64,`Int64`>> value. Note that this may lose precision. */ lua_pushnumber(L, (lua_Number)(checkInt64(L,1))); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_CONSTRUCTOR Int64_fromhex(lua_State* L) { - /* Creates an <<lua_class_Int64,`Int64`>> object from the given hexadecimal string. - @since 1.11.3 - */ + /* Creates an <<lua_class_Int64,`Int64`>> object from the given hexadecimal string. */ #define WSLUA_ARG_Int64_fromhex_HEX 1 /* The hex-ASCII Lua string. */ - guint64 result = 0; + uint64_t result = 0; size_t len = 0; - const gchar *s = luaL_checklstring(L,WSLUA_ARG_Int64_fromhex_HEX,&len); + const char *s = luaL_checklstring(L,WSLUA_ARG_Int64_fromhex_HEX,&len); if (len > 0) { if (sscanf(s, "%" SCNx64, &result) != 1) { return luaL_error(L, "Error decoding the passed-in hex string"); } } - pushInt64(L,(gint64)result); + pushInt64(L,(int64_t)result); WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>> object. */ } WSLUA_METHOD Int64_tohex(lua_State* L) { - /* Returns a hexadecimal string of the <<lua_class_Int64,`Int64`>> value. - @since 1.11.3 - */ + /* Returns a hexadecimal string of the <<lua_class_Int64,`Int64`>> value. */ #define WSLUA_OPTARG_Int64_tohex_NUMBYTES 2 /* The number of hex chars/nibbles to generate. A negative value generates uppercase. Default is 16. */ - gint64 b = getInt64(L,1); + int64_t b = getInt64(L,1); lua_Integer n = luaL_optinteger(L, WSLUA_OPTARG_Int64_tohex_NUMBYTES, 16); - const gchar *hexdigits = "0123456789abcdef"; - gchar buf[16]; + const char *hexdigits = "0123456789abcdef"; + char buf[16]; lua_Integer i; if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; } if (n > 16) n = 16; @@ -321,34 +310,31 @@ WSLUA_METHOD Int64_tohex(lua_State* L) { WSLUA_METHOD Int64_higher(lua_State* L) { /* Returns a Lua number of the higher 32 bits of the <<lua_class_Int64,`Int64`>> value. A negative <<lua_class_Int64,`Int64`>> will return a negative Lua number. - @since 1.11.3 */ - gint64 num = getInt64(L,1); - gint64 b = num; + int64_t num = getInt64(L,1); + int64_t b = num; lua_Number n = 0; if (b < 0) b = -b; /* masking/shifting negative int64 isn't working on some platforms */ - b &= G_GUINT64_CONSTANT(0x7FFFFFFF00000000); + b &= UINT64_C(0x7FFFFFFF00000000); b >>= 32; - n = (lua_Number)(guint32)(b & G_GUINT64_CONSTANT(0x00000000FFFFFFFFF)); + n = (lua_Number)(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF)); if (num < 0) n = -n; lua_pushnumber(L,n); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_METHOD Int64_lower(lua_State* L) { - /* Returns a Lua number of the lower 32 bits of the <<lua_class_Int64,`Int64`>> value. This will always be positive. - @since 1.11.3 - */ - gint64 b = getInt64(L,1); + /* Returns a Lua number of the lower 32 bits of the <<lua_class_Int64,`Int64`>> value. This will always be positive. */ + int64_t b = getInt64(L,1); if (b < 0) b = -b; /* masking/shifting negative int64 isn't working on some platforms */ - lua_pushnumber(L,(guint32)(b & G_GUINT64_CONSTANT(0x00000000FFFFFFFFF))); + lua_pushnumber(L,(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF))); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_METAMETHOD Int64__tostring(lua_State* L) { /* Converts the <<lua_class_Int64,`Int64`>> into a string of decimal digits. */ - gint64 num = getInt64(L,1); - gchar s[LUATYPE64_STRING_SIZE]; + int64_t num = getInt64(L,1); + char s[LUATYPE64_STRING_SIZE]; if (snprintf(s, LUATYPE64_STRING_SIZE, "%" PRId64, num) < 0) { return luaL_error(L, "Error writing Int64 to a string"); } @@ -357,9 +343,7 @@ WSLUA_METAMETHOD Int64__tostring(lua_State* L) { } WSLUA_METAMETHOD Int64__unm(lua_State* L) { - /* Returns the negative of the <<lua_class_Int64,`Int64`>> as a new <<lua_class_Int64,`Int64`>>. - @since 1.11.3 - */ + /* Returns the negative of the <<lua_class_Int64,`Int64`>> as a new <<lua_class_Int64,`Int64`>>. */ pushInt64(L,-(getInt64(L,1))); WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>>. */ } @@ -372,30 +356,23 @@ WSLUA_METAMETHOD Int64__unm(lua_State* L) { return 1 WSLUA_METAMETHOD Int64__add(lua_State* L) { - /* Adds two <<lua_class_Int64,`Int64`>> together and returns a new one. The value may wrapped. - @since 1.11.3 - */ + /* Adds two <<lua_class_Int64,`Int64`>> together and returns a new one. The value may wrapped. */ WSLUA_MATH_OP_FUNC(Int64,+); } WSLUA_METAMETHOD Int64__sub(lua_State* L) { - /* Subtracts two <<lua_class_Int64,`Int64`>> and returns a new one. The value may wrapped. - @since 1.11.3 - */ + /* Subtracts two <<lua_class_Int64,`Int64`>> and returns a new one. The value may wrapped. */ WSLUA_MATH_OP_FUNC(Int64,-); } WSLUA_METAMETHOD Int64__mul(lua_State* L) { - /* Multiplies two <<lua_class_Int64,`Int64`>> and returns a new one. The value may truncated. - @since 1.11.3 - */ + /* Multiplies two <<lua_class_Int64,`Int64`>> and returns a new one. The value may truncated. */ WSLUA_MATH_OP_FUNC(Int64,*); } WSLUA_METAMETHOD Int64__div(lua_State* L) { /* Divides two <<lua_class_Int64,`Int64`>> and returns a new one. Integer divide, no remainder. Trying to divide by zero results in a Lua error. - @since 1.11.3 */ Int64 num1 = getInt64(L,1); Int64 num2 = getInt64(L,2); @@ -409,7 +386,6 @@ WSLUA_METAMETHOD Int64__div(lua_State* L) { WSLUA_METAMETHOD Int64__mod(lua_State* L) { /* Divides two <<lua_class_Int64,`Int64`>> and returns a new one of the remainder. Trying to modulo by zero results in a Lua error. - @since 1.11.3 */ Int64 num1 = getInt64(L,1); Int64 num2 = getInt64(L,2); @@ -423,13 +399,12 @@ WSLUA_METAMETHOD Int64__mod(lua_State* L) { WSLUA_METAMETHOD Int64__pow(lua_State* L) { /* The first <<lua_class_Int64,`Int64`>> is taken to the power of the second <<lua_class_Int64,`Int64`>>, returning a new one. This may truncate the value. - @since 1.11.3 */ - gint64 num1 = getInt64(L,1); - gint64 num2 = getInt64(L,2); - gint64 result; + int64_t num1 = getInt64(L,1); + int64_t num2 = getInt64(L,2); + int64_t result; if (num1 == 2) { - result = (num2 >= 8 * (gint64) sizeof(gint64)) ? 0 : ((gint64)1 << num2); + result = (num2 >= 8 * (int64_t) sizeof(int64_t)) ? 0 : ((int64_t)1 << num2); } else { for (result = 1; num2 > 0; num2 >>= 1) { @@ -448,36 +423,28 @@ WSLUA_METAMETHOD Int64__pow(lua_State* L) { return 1 WSLUA_METAMETHOD Int64__eq(lua_State* L) { - /* Returns `true` if both <<lua_class_Int64,`Int64`>> are equal. - @since 1.11.3 - */ + /* Returns `true` if both <<lua_class_Int64,`Int64`>> are equal. */ WSLUA_COMP_OP_FUNC(Int64,==); } WSLUA_METAMETHOD Int64__lt(lua_State* L) { - /* Returns `true` if first <<lua_class_Int64,`Int64`>> is less than the second. - @since 1.11.3 - */ + /* Returns `true` if first <<lua_class_Int64,`Int64`>> is less than the second. */ WSLUA_COMP_OP_FUNC(Int64,<); } WSLUA_METAMETHOD Int64__le(lua_State* L) { - /* Returns `true` if the first <<lua_class_Int64,`Int64`>> is less than or equal to the second. - @since 1.11.3 - */ + /* Returns `true` if the first <<lua_class_Int64,`Int64`>> is less than or equal to the second. */ WSLUA_COMP_OP_FUNC(Int64,<=); } WSLUA_METHOD Int64_bnot(lua_State* L) { - /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'not' operation. - @since 1.11.3 - */ + /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'not' operation. */ pushInt64(L,~(getInt64(L,1))); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } #define WSLUA_BIT_OP_FUNC(obj,op) \ - gint32 i; \ + int32_t i; \ obj num = get##obj(L,1); \ for (i = lua_gettop(L); i > 1; i--) { \ num op get##obj(L,i); \ @@ -488,7 +455,6 @@ WSLUA_METHOD Int64_bnot(lua_State* L) { WSLUA_METHOD Int64_band(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'and' operation with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(Int64,&=); } @@ -496,7 +462,6 @@ WSLUA_METHOD Int64_band(lua_State* L) { WSLUA_METHOD Int64_bor(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'or' operation, with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(Int64,|=); } @@ -504,7 +469,6 @@ WSLUA_METHOD Int64_bor(lua_State* L) { WSLUA_METHOD Int64_bxor(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'xor' operation, with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(Int64,^=); } @@ -512,35 +476,32 @@ WSLUA_METHOD Int64_bxor(lua_State* L) { WSLUA_METHOD Int64_lshift(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise logical left-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_Int64_lshift_NUMBITS 2 /* The number of bits to left-shift by. */ - guint64 b = (guint64) getInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_lshift_NUMBITS); - pushInt64(L,(gint64)(b << n)); + uint64_t b = (uint64_t) getInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_lshift_NUMBITS); + pushInt64(L,(int64_t)(b << n)); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } WSLUA_METHOD Int64_rshift(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise logical right-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_Int64_rshift_NUMBITS 2 /* The number of bits to right-shift by. */ - guint64 b = (guint64) getInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_rshift_NUMBITS); - pushInt64(L,(gint64)(b >> n)); + uint64_t b = (uint64_t) getInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_rshift_NUMBITS); + pushInt64(L,(int64_t)(b >> n)); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } WSLUA_METHOD Int64_arshift(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise arithmetic right-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_Int64_arshift_NUMBITS 2 /* The number of bits to right-shift by. */ - gint64 b = getInt64(L,1); - gint32 n = wslua_checkgint32(L,WSLUA_ARG_Int64_arshift_NUMBITS); + int64_t b = getInt64(L,1); + int32_t n = wslua_checkint32(L,WSLUA_ARG_Int64_arshift_NUMBITS); pushInt64(L,(b >> n)); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } @@ -548,41 +509,38 @@ WSLUA_METHOD Int64_arshift(lua_State* L) { WSLUA_METHOD Int64_rol(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise left rotation operation, by the given number of bits (up to 63). - @since 1.11.3 */ #define WSLUA_ARG_Int64_rol_NUMBITS 2 /* The number of bits to roll left by. */ - guint64 b = (guint64) getInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_rol_NUMBITS); - pushInt64(L,(gint64)((b << n) | (b >> (64-n)))); + uint64_t b = (uint64_t) getInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_rol_NUMBITS); + pushInt64(L,(int64_t)((b << n) | (b >> (64-n)))); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } WSLUA_METHOD Int64_ror(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise right rotation operation, by the given number of bits (up to 63). - @since 1.11.3 */ #define WSLUA_ARG_Int64_ror_NUMBITS 2 /* The number of bits to roll right by. */ - guint64 b = (guint64) getInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_ror_NUMBITS); - pushInt64(L,(gint64)((b << (64-n)) | (b >> n))); + uint64_t b = (uint64_t) getInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_ror_NUMBITS); + pushInt64(L,(int64_t)((b << (64-n)) | (b >> n))); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } WSLUA_METHOD Int64_bswap(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bytes swapped. This can be used to convert little-endian 64-bit numbers to big-endian 64 bit numbers or vice versa. - @since 1.11.3 */ - guint64 b = (guint64) getInt64(L,1); - guint64 result = 0; + uint64_t b = (uint64_t) getInt64(L,1); + uint64_t result = 0; size_t i; - for (i = 0; i < sizeof(gint64); i++) { + for (i = 0; i < sizeof(int64_t); i++) { result <<= 8; - result |= (b & G_GUINT64_CONSTANT(0x00000000000000FF)); + result |= (b & UINT64_C(0x00000000000000FF)); b >>= 8; } - pushInt64(L,(gint64)result); + pushInt64(L,(int64_t)result); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } @@ -646,15 +604,15 @@ WSLUA_CLASS_DEFINE_BASE(UInt64,NOP,0); Note the caveats <<lua_module_Int64,listed above>>. */ -/* A checkUInt64 but that also auto-converts numbers, strings, and <<lua_class_Int64,`Int64`>> to a guint64. */ -guint64 getUInt64(lua_State *L, int i) +/* A checkUInt64 but that also auto-converts numbers, strings, and <<lua_class_Int64,`Int64`>> to a uint64_t. */ +uint64_t getUInt64(lua_State *L, int i) { - gchar *end = NULL; + char *end = NULL; (void) end; switch (lua_type(L,i)) { case LUA_TNUMBER: - return wslua_checkguint64(L,i); + return wslua_checkuint64(L,i); case LUA_TSTRING: return g_ascii_strtoull(luaL_checkstring(L,i), &end, 0); case LUA_TUSERDATA: @@ -668,36 +626,34 @@ guint64 getUInt64(lua_State *L, int i) } /* Encodes <<lua_class_UInt64,`UInt64`>> userdata into Lua string struct with given endianness */ -void UInt64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittleEndian) { - guint64 value = checkUInt64(L,idx); - gint8 buff[sizeof(guint64)]; +void UInt64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian) { + uint64_t value = checkUInt64(L,idx); + int8_t buff[sizeof(uint64_t)]; if (asLittleEndian) { - guint i; - for (i = 0; i < sizeof(guint64); i++) { + unsigned i; + for (i = 0; i < sizeof(uint64_t); i++) { buff[i] = (value & 0xff); value >>= 8; } } else { - gint i; - for (i = sizeof(guint64) - 1; i >= 0; i--) { + int i; + for (i = sizeof(uint64_t) - 1; i >= 0; i--) { buff[i] = (value & 0xff); value >>= 8; } } - luaL_addlstring(b, (char*)buff, sizeof(guint64)); + luaL_addlstring(b, (char*)buff, sizeof(uint64_t)); } WSLUA_METHOD UInt64_encode(lua_State* L) { - /* Encodes the <<lua_class_UInt64,`UInt64`>> number into an 8-byte Lua binary string, using given endianness. - @since 1.11.3 - */ + /* Encodes the <<lua_class_UInt64,`UInt64`>> number into an 8-byte Lua binary string, using given endianness. */ #define WSLUA_OPTARG_UInt64_encode_ENDIAN 2 /* If set to true then little-endian is used, if false then big-endian; if missing or `nil`, native host endian. */ luaL_Buffer b; - gboolean asLittleEndian = IS_LITTLE_ENDIAN; + bool asLittleEndian = IS_LITTLE_ENDIAN; if (lua_gettop(L) >= 2) { if (lua_type(L,2) == LUA_TBOOLEAN) @@ -713,20 +669,20 @@ WSLUA_METHOD UInt64_encode(lua_State* L) { } /* Decodes from string buffer struct into <<lua_class_UInt64,`UInt64`>> userdata, with given endianness. */ -int UInt64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian) { - guint64 value = 0; - gint i; +int UInt64_unpack(lua_State* L, const char *buff, bool asLittleEndian) { + uint64_t value = 0; + int i; if (asLittleEndian) { - for (i = sizeof(guint64) - 1; i >= 0; i--) { + for (i = sizeof(uint64_t) - 1; i >= 0; i--) { value <<= 8; - value |= (guint64)(guchar)buff[i]; + value |= (uint64_t)(unsigned char)buff[i]; } } else { - for (i = 0; i < (gint) sizeof(guint64); i++) { + for (i = 0; i < (int) sizeof(uint64_t); i++) { value <<= 8; - value |= (guint64)(guchar)buff[i]; + value |= (uint64_t)(unsigned char)buff[i]; } } @@ -735,23 +691,21 @@ int UInt64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian) { } WSLUA_CONSTRUCTOR UInt64_decode(lua_State* L) { - /* Decodes an 8-byte Lua binary string, using given endianness, into a new <<lua_class_UInt64,`UInt64`>> object. - @since 1.11.3 - */ + /* Decodes an 8-byte Lua binary string, using given endianness, into a new <<lua_class_UInt64,`UInt64`>> object. */ #define WSLUA_ARG_UInt64_decode_STRING 1 /* The Lua string containing a binary 64-bit integer. */ #define WSLUA_OPTARG_UInt64_decode_ENDIAN 2 /* If set to true then little-endian is used, if false then big-endian; if missing or `nil`, native host endian. */ - gboolean asLittleEndian = IS_LITTLE_ENDIAN; + bool asLittleEndian = IS_LITTLE_ENDIAN; size_t len = 0; - const gchar *s = luaL_checklstring(L, WSLUA_ARG_UInt64_decode_STRING, &len); + const char *s = luaL_checklstring(L, WSLUA_ARG_UInt64_decode_STRING, &len); if (lua_gettop(L) >= WSLUA_OPTARG_UInt64_decode_ENDIAN) { if (lua_type(L,WSLUA_OPTARG_UInt64_decode_ENDIAN) == LUA_TBOOLEAN) asLittleEndian = lua_toboolean(L,WSLUA_OPTARG_UInt64_decode_ENDIAN); } - if (len == sizeof(guint64)) { + if (len == sizeof(uint64_t)) { UInt64_unpack(L, s, asLittleEndian); } else { lua_pushnil(L); @@ -761,26 +715,24 @@ WSLUA_CONSTRUCTOR UInt64_decode(lua_State* L) { } WSLUA_CONSTRUCTOR UInt64_new(lua_State* L) { - /* Creates a <<lua_class_UInt64,`UInt64`>> Object. - @since 1.11.3 - */ + /* Creates a <<lua_class_UInt64,`UInt64`>> object. */ #define WSLUA_OPTARG_UInt64_new_VALUE 1 /* A number, <<lua_class_UInt64,`UInt64`>>, <<lua_class_Int64,`Int64`>>, or string of digits to assign the value of the new <<lua_class_UInt64,`UInt64`>>. Default is 0. */ #define WSLUA_OPTARG_UInt64_new_HIGHVALUE 2 /* If this is a number and the first argument was a number, then the first will be treated as a lower 32 bits, and this is the high-order 32-bit number. */ - guint64 value = 0; + uint64_t value = 0; if (lua_gettop(L) >= 1) { switch(lua_type(L, WSLUA_OPTARG_UInt64_new_VALUE)) { case LUA_TNUMBER: - value = wslua_toguint64(L, WSLUA_OPTARG_UInt64_new_VALUE); + value = wslua_touint64(L, WSLUA_OPTARG_UInt64_new_VALUE); if (lua_gettop(L) == 2 && lua_type(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE) == LUA_TNUMBER) { - guint64 h = wslua_toguint64(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE); - value &= G_GUINT64_CONSTANT(0x00000000FFFFFFFF); - h <<= 32; h &= G_GUINT64_CONSTANT(0xFFFFFFFF00000000); + uint64_t h = wslua_touint64(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE); + value &= UINT64_C(0x00000000FFFFFFFF); + h <<= 32; h &= UINT64_C(0xFFFFFFFF00000000); value += h; } break; @@ -800,42 +752,34 @@ WSLUA_CONSTRUCTOR UInt64_new(lua_State* L) { } WSLUA_METAMETHOD UInt64__call(lua_State* L) { - /* Creates a <<lua_class_UInt64,`UInt64`>> object. - @since 1.11.3 - */ + /* Creates a <<lua_class_UInt64,`UInt64`>> object. */ lua_remove(L,1); /* remove the table */ WSLUA_RETURN(UInt64_new(L)); /* The new <<lua_class_UInt64,`UInt64`>> object. */ } WSLUA_CONSTRUCTOR UInt64_max(lua_State* L) { - /* Creates a <<lua_class_UInt64,`UInt64`>> of the maximum possible value. In other words, this should return an UInt64 object of the number 18,446,744,073,709,551,615. - @since 1.11.3 - */ - pushUInt64(L,G_MAXUINT64); + /* Creates a <<lua_class_UInt64,`UInt64`>> of the maximum possible value. In other words, this should return an UInt64 object of the number 18,446,744,073,709,551,615. */ + pushUInt64(L,UINT64_MAX); WSLUA_RETURN(1); /* The maximum value. */ } WSLUA_CONSTRUCTOR UInt64_min(lua_State* L) { - /* Creates a <<lua_class_UInt64,`UInt64`>> of the minimum possible value. In other words, this should return an UInt64 object of the number 0. - @since 1.11.3 - */ + /* Creates a <<lua_class_UInt64,`UInt64`>> of the minimum possible value. In other words, this should return an UInt64 object of the number 0. */ pushUInt64(L,0); WSLUA_RETURN(1); /* The minimum value. */ } WSLUA_METHOD UInt64_tonumber(lua_State* L) { - /* Returns a Lua number of the <<lua_class_UInt64,`UInt64`>> value. This may lose precision. - @since 1.11.3 - */ + /* Returns a Lua number of the <<lua_class_UInt64,`UInt64`>> value. This may lose precision. */ lua_pushnumber(L,(lua_Number)(checkUInt64(L,1))); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_METAMETHOD UInt64__tostring(lua_State* L) { /* Converts the <<lua_class_UInt64,`UInt64`>> into a string. */ - guint64 num = getUInt64(L,1); - gchar s[LUATYPE64_STRING_SIZE]; - if (snprintf(s, LUATYPE64_STRING_SIZE, "%" PRIu64,(guint64)num) < 0) { + uint64_t num = getUInt64(L,1); + char s[LUATYPE64_STRING_SIZE]; + if (snprintf(s, LUATYPE64_STRING_SIZE, "%" PRIu64,(uint64_t)num) < 0) { return luaL_error(L, "Error writing UInt64 to a string"); } lua_pushstring(L,s); @@ -843,13 +787,11 @@ WSLUA_METAMETHOD UInt64__tostring(lua_State* L) { } WSLUA_CONSTRUCTOR UInt64_fromhex(lua_State* L) { - /* Creates a <<lua_class_UInt64,`UInt64`>> object from the given hex string. - @since 1.11.3 - */ + /* Creates a <<lua_class_UInt64,`UInt64`>> object from the given hex string. */ #define WSLUA_ARG_UInt64_fromhex_HEX 1 /* The hex-ASCII Lua string. */ - guint64 result = 0; + uint64_t result = 0; size_t len = 0; - const gchar *s = luaL_checklstring(L,WSLUA_ARG_UInt64_fromhex_HEX,&len); + const char *s = luaL_checklstring(L,WSLUA_ARG_UInt64_fromhex_HEX,&len); if (len > 0) { if (sscanf(s, "%" SCNx64, &result) != 1) { @@ -861,15 +803,13 @@ WSLUA_CONSTRUCTOR UInt64_fromhex(lua_State* L) { } WSLUA_METHOD UInt64_tohex(lua_State* L) { - /* Returns a hex string of the <<lua_class_UInt64,`UInt64`>> value. - @since 1.11.3 - */ + /* Returns a hex string of the <<lua_class_UInt64,`UInt64`>> value. */ #define WSLUA_OPTARG_UInt64_tohex_NUMBYTES 2 /* The number of hex-chars/nibbles to generate. Negative means uppercase Default is 16. */ - guint64 b = getUInt64(L,1); + uint64_t b = getUInt64(L,1); lua_Integer n = luaL_optinteger(L, WSLUA_OPTARG_UInt64_tohex_NUMBYTES, 16); - const gchar *hexdigits = "0123456789abcdef"; - gchar buf[16]; + const char *hexdigits = "0123456789abcdef"; + char buf[16]; lua_Integer i; if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; } if (n > 16) n = 16; @@ -880,56 +820,47 @@ WSLUA_METHOD UInt64_tohex(lua_State* L) { WSLUA_METHOD UInt64_higher(lua_State* L) { /* Returns a Lua number of the higher 32 bits of the <<lua_class_UInt64,`UInt64`>> value. */ - guint64 num = getUInt64(L,1); - guint64 b = num; + uint64_t num = getUInt64(L,1); + uint64_t b = num; lua_Number n = 0; - b &= G_GUINT64_CONSTANT(0xFFFFFFFF00000000); + b &= UINT64_C(0xFFFFFFFF00000000); b >>= 32; - n = (lua_Number)(guint32)(b & G_GUINT64_CONSTANT(0x00000000FFFFFFFFF)); + n = (lua_Number)(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF)); lua_pushnumber(L,n); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_METHOD UInt64_lower(lua_State* L) { /* Returns a Lua number of the lower 32 bits of the <<lua_class_UInt64,`UInt64`>> value. */ - guint64 b = getUInt64(L,1); - lua_pushnumber(L,(guint32)(b & G_GUINT64_CONSTANT(0x00000000FFFFFFFFF))); + uint64_t b = getUInt64(L,1); + lua_pushnumber(L,(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF))); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_METAMETHOD UInt64__unm(lua_State* L) { - /* Returns the <<lua_class_UInt64,`UInt64`>> in a new <<lua_class_UInt64,`UInt64`>>, since unsigned integers can't be negated. - @since 1.11.3 - */ + /* Returns the <<lua_class_UInt64,`UInt64`>> in a new <<lua_class_UInt64,`UInt64`>>, since unsigned integers can't be negated. */ pushUInt64(L,getUInt64(L,1)); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } WSLUA_METAMETHOD UInt64__add(lua_State* L) { - /* Adds two <<lua_class_UInt64,`UInt64`>> together and returns a new one. This may wrap the value. - @since 1.11.3 - */ + /* Adds two <<lua_class_UInt64,`UInt64`>> together and returns a new one. This may wrap the value. */ WSLUA_MATH_OP_FUNC(UInt64,+); } WSLUA_METAMETHOD UInt64__sub(lua_State* L) { - /* Subtracts two <<lua_class_UInt64,`UInt64`>> and returns a new one. This may wrap the value. - @since 1.11.3 - */ + /* Subtracts two <<lua_class_UInt64,`UInt64`>> and returns a new one. This may wrap the value. */ WSLUA_MATH_OP_FUNC(UInt64,-); } WSLUA_METAMETHOD UInt64__mul(lua_State* L) { - /* Multiplies two <<lua_class_UInt64,`UInt64`>> and returns a new one. This may truncate the value. - @since 1.11.3 - */ + /* Multiplies two <<lua_class_UInt64,`UInt64`>> and returns a new one. This may truncate the value. */ WSLUA_MATH_OP_FUNC(UInt64,*); } WSLUA_METAMETHOD UInt64__div(lua_State* L) { /* Divides two <<lua_class_UInt64,`UInt64`>> and returns a new one. Integer divide, no remainder. Trying to divide by zero results in a Lua error. - @since 1.11.3 */ UInt64 num1 = getUInt64(L,1); UInt64 num2 = getUInt64(L,2); @@ -943,7 +874,6 @@ WSLUA_METAMETHOD UInt64__div(lua_State* L) { WSLUA_METAMETHOD UInt64__mod(lua_State* L) { /* Divides two <<lua_class_UInt64,`UInt64`>> and returns a new one of the remainder. Trying to modulo by zero results in a Lua error. - @since 1.11.3 */ UInt64 num1 = getUInt64(L,1); UInt64 num2 = getUInt64(L,2); @@ -957,13 +887,12 @@ WSLUA_METAMETHOD UInt64__mod(lua_State* L) { WSLUA_METAMETHOD UInt64__pow(lua_State* L) { /* The first <<lua_class_UInt64,`UInt64`>> is taken to the power of the second <<lua_class_UInt64,`UInt64`>>/number, returning a new one. This may truncate the value. - @since 1.11.3 */ - guint64 num1 = getUInt64(L,1); - guint64 num2 = getUInt64(L,2); - guint64 result; + uint64_t num1 = getUInt64(L,1); + uint64_t num2 = getUInt64(L,2); + uint64_t result; if (num1 == 2) { - result = (num2 >= 8 * (guint64) sizeof(guint64)) ? 0 : ((guint64)1 << num2); + result = (num2 >= 8 * (uint64_t) sizeof(uint64_t)) ? 0 : ((uint64_t)1 << num2); } else { for (result = 1; num2 > 0; num2 >>= 1) { @@ -976,30 +905,22 @@ WSLUA_METAMETHOD UInt64__pow(lua_State* L) { } WSLUA_METAMETHOD UInt64__eq(lua_State* L) { - /* Returns true if both <<lua_class_UInt64,`UInt64`>> are equal. - @since 1.11.3 - */ + /* Returns true if both <<lua_class_UInt64,`UInt64`>> are equal. */ WSLUA_COMP_OP_FUNC(UInt64,==); } WSLUA_METAMETHOD UInt64__lt(lua_State* L) { - /* Returns true if first <<lua_class_UInt64,`UInt64`>> is less than the second. - @since 1.11.3 - */ + /* Returns true if first <<lua_class_UInt64,`UInt64`>> is less than the second. */ WSLUA_COMP_OP_FUNC(UInt64,<); } WSLUA_METAMETHOD UInt64__le(lua_State* L) { - /* Returns true if first <<lua_class_UInt64,`UInt64`>> is less than or equal to the second. - @since 1.11.3 - */ + /* Returns true if first <<lua_class_UInt64,`UInt64`>> is less than or equal to the second. */ WSLUA_COMP_OP_FUNC(UInt64,<=); } WSLUA_METHOD UInt64_bnot(lua_State* L) { - /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'not' operation. - @since 1.11.3 - */ + /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'not' operation. */ pushUInt64(L,~(getUInt64(L,1))); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1007,7 +928,6 @@ WSLUA_METHOD UInt64_bnot(lua_State* L) { WSLUA_METHOD UInt64_band(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'and' operation, with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(UInt64,&=); } @@ -1015,7 +935,6 @@ WSLUA_METHOD UInt64_band(lua_State* L) { WSLUA_METHOD UInt64_bor(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'or' operation, with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(UInt64,|=); } @@ -1023,7 +942,6 @@ WSLUA_METHOD UInt64_bor(lua_State* L) { WSLUA_METHOD UInt64_bxor(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'xor' operation, with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(UInt64,^=); } @@ -1031,11 +949,10 @@ WSLUA_METHOD UInt64_bxor(lua_State* L) { WSLUA_METHOD UInt64_lshift(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise logical left-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_UInt64_lshift_NUMBITS 2 /* The number of bits to left-shift by. */ - guint64 b = getUInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_lshift_NUMBITS); + uint64_t b = getUInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_lshift_NUMBITS); pushUInt64(L,(b << n)); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1043,11 +960,10 @@ WSLUA_METHOD UInt64_lshift(lua_State* L) { WSLUA_METHOD UInt64_rshift(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise logical right-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_UInt64_rshift_NUMBITS 2 /* The number of bits to right-shift by. */ - guint64 b = getUInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_rshift_NUMBITS); + uint64_t b = getUInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_rshift_NUMBITS); pushUInt64(L,(b >> n)); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1055,11 +971,10 @@ WSLUA_METHOD UInt64_rshift(lua_State* L) { WSLUA_METHOD UInt64_arshift(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise arithmetic right-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_UInt64_arshift_NUMBITS 2 /* The number of bits to right-shift by. */ - guint64 b = getUInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_arshift_NUMBITS); + uint64_t b = getUInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_arshift_NUMBITS); pushUInt64(L,(b >> n)); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1067,11 +982,10 @@ WSLUA_METHOD UInt64_arshift(lua_State* L) { WSLUA_METHOD UInt64_rol(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise left rotation operation, by the given number of bits (up to 63). - @since 1.11.3 */ #define WSLUA_ARG_UInt64_rol_NUMBITS 2 /* The number of bits to roll left by. */ - guint64 b = getUInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_rol_NUMBITS); + uint64_t b = getUInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_rol_NUMBITS); pushUInt64(L,((b << n) | (b >> (64-n)))); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1079,11 +993,10 @@ WSLUA_METHOD UInt64_rol(lua_State* L) { WSLUA_METHOD UInt64_ror(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise right rotation operation, by the given number of bits (up to 63). - @since 1.11.3 */ #define WSLUA_ARG_UInt64_ror_NUMBITS 2 /* The number of bits to roll right by. */ - guint64 b = getUInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_ror_NUMBITS); + uint64_t b = getUInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_ror_NUMBITS); pushUInt64(L,((b << (64-n)) | (b >> n))); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1091,14 +1004,13 @@ WSLUA_METHOD UInt64_ror(lua_State* L) { WSLUA_METHOD UInt64_bswap(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bytes swapped. This can be used to convert little-endian 64-bit numbers to big-endian 64 bit numbers or vice versa. - @since 1.11.3 */ - guint64 b = getUInt64(L,1); - guint64 result = 0; + uint64_t b = getUInt64(L,1); + uint64_t result = 0; size_t i; - for (i = 0; i < sizeof(guint64); i++) { + for (i = 0; i < sizeof(uint64_t); i++) { result <<= 8; - result |= (b & G_GUINT64_CONSTANT(0x00000000000000FF)); + result |= (b & UINT64_C(0x00000000000000FF)); b >>= 8; } pushUInt64(L,result); |