regen pidl all: rm epan/dissectors/pidl/*-stamp; pushd epan/dissectors/pidl/ && make...
[wireshark-sm.git] / epan / wslua / wslua_int64.c
blobb7b7d3c8d275c99b133ee55f70c491ebc6571706
1 /*
2 * A Lua userdata object for 64-bit signed/unsigned integers.
4 * I, Hadriel Kaplan, the author of wslua_int6464.c, wish to put it in
5 * the Public Domain. That is not universally accepted, however,
6 * so you may license it under the FreeBSD License instead, which is an open
7 * source license approved for GPL use as well as commercial etc.
8 * It's even less restrictive than the MIT license, because it requires
9 * no attribution anywhere - I don't *want* attribution.
11 Copyright (C) 2013 Hadriel Kaplan <hadrielk@yahoo.com>
12 All rights reserved.
14 SPDX-License-Identifier: BSD-2-Clause
16 The views and conclusions contained in the software and documentation are those
17 of the authors and should not be interpreted as representing official policies,
18 either expressed or implied, of the FreeBSD Project.
21 #include "config.h"
23 #include "wslua.h"
26 WSLUA_MODULE Int64 Handling 64-bit Integers
28 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.
30 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.
31 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).
33 Therefore, in order to count higher than 2^53 in integers, we need a true integer type.
34 The way this is done is with an explicit 'Int64' or 'UInt64' object (i.e., Lua userdata).
35 This object has metamethods for all of the math and comparison operators, so you can handle it like any number variable.
36 For the math operators, it can even be mixed with plain Lua numbers.
38 For example 'my64num = my64num + 1' will work even if 'my64num' is a <<lua_class_Int64,`Int64`>> or <<lua_class_UInt64,`UInt64`>> object.
39 Note that comparison operators ('==','$$<=$$','>', etc.) will not work with plain numbers -- only other Int64/UInt64 objects.
40 This is a limitation of Lua itself, in terms of how it handles operator overloading.
42 [WARNING]
43 ====
44 Many of the UInt64/Int64 functions accept a Lua number as an argument.
45 You should be very careful to never use Lua numbers bigger than 32 bits (i.e., the number value 4,294,967,295 or the literal 0xFFFFFFFF) for such arguments, because Lua itself does not handle bigger numbers consistently across platforms (32-bit vs. 64-bit systems), and because a Lua number is a C-code double which cannot have more than 53 bits of precision.
46 Instead, use a Int64 or UInt64 for the argument.
47 ====
49 For example, do this...
51 [source,lua]
52 ----
53 local mynum = UInt64(0x2b89dd1e, 0x3f91df0b)
54 ----
56 ...instead of this:
58 [source,lua]
59 ----
60 -- Bad. Leads to inconsistent results across platforms
61 local mynum = UInt64(0x3f91df0b2b89dd1e)
62 ----
64 And do this...
66 [source,lua]
67 ----
68 local masked = mynum:band(UInt64(0, 0xFFFFFFFF))
69 ----
71 ...instead of this:
73 [source,lua]
74 ----
75 -- Bad. Leads to inconsistent results across platforms
76 local masked = mynum:band(0xFFFFFFFF00000000)
77 ----
79 [NOTE]
80 ====
81 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.
82 (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.)
83 Wireshark 4.4 and later will use the Lua integer type where possible, but as storing
84 64-bit unsigned integers in a Lua Integer can result in signed number overflow, `UInt64`
85 is still necessary. `Int64` is also still available for use.
86 ====
90 #define LUATYPE64_STRING_SIZE 21 /* string to hold 18446744073709551615 */
92 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
93 #define IS_LITTLE_ENDIAN true
94 #else
95 #define IS_LITTLE_ENDIAN false
96 #endif
98 WSLUA_CLASS_DEFINE_BASE(Int64,NOP,0);
100 <<lua_class_Int64,`Int64`>> represents a 64 bit signed integer.
102 Note the caveats <<lua_module_Int64,listed above>>.
105 /* A checkInt64 but that also auto-converts numbers, strings, and UINT64 to a int64_t */
106 static int64_t getInt64(lua_State *L, int i)
108 char *end = NULL;
109 (void) end;
110 switch (lua_type(L,i))
112 case LUA_TNUMBER:
113 return wslua_checkint64(L,i);
114 case LUA_TSTRING:
115 return g_ascii_strtoll(luaL_checkstring(L,i),&end,10);
116 case LUA_TUSERDATA:
117 if (isUInt64(L, i)) {
118 return (Int64) toUInt64(L, i);
120 /* fall through */
121 default:
122 return checkInt64(L,i);
127 /* Encodes Int64 userdata into Lua string struct with given endianness */
128 void Int64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian) {
129 int64_t value = checkInt64(L,idx);
130 int8_t buff[sizeof(int64_t)];
132 if (asLittleEndian) {
133 unsigned i;
134 for (i = 0; i < sizeof(int64_t); i++) {
135 buff[i] = (value & 0xff);
136 value >>= 8;
139 else {
140 int i;
141 for (i = sizeof(int64_t) - 1; i >= 0; i--) {
142 buff[i] = (value & 0xff);
143 value >>= 8;
146 luaL_addlstring(b, (char*)buff, sizeof(int64_t));
149 WSLUA_METHOD Int64_encode(lua_State* L) {
150 /* Encodes the <<lua_class_Int64,`Int64`>> number into an 8-byte Lua string using the given endianness. */
151 #define WSLUA_OPTARG_Int64_encode_ENDIAN 2 /* If set to true then little-endian is used,
152 if false then big-endian; if missing or `nil`,
153 native host endian. */
154 luaL_Buffer b;
155 bool asLittleEndian = IS_LITTLE_ENDIAN;
157 if (lua_gettop(L) >= WSLUA_OPTARG_Int64_encode_ENDIAN) {
158 if (lua_type(L,WSLUA_OPTARG_Int64_encode_ENDIAN) == LUA_TBOOLEAN)
159 asLittleEndian = lua_toboolean(L,WSLUA_OPTARG_Int64_encode_ENDIAN);
162 luaL_buffinit(L, &b);
164 Int64_pack(L, &b, 1, asLittleEndian);
166 luaL_pushresult(&b);
167 WSLUA_RETURN(1); /* The Lua string. */
170 /* Decodes from string buffer struct into Int64 userdata, with given endianness */
171 int Int64_unpack(lua_State* L, const char *buff, bool asLittleEndian) {
172 int64_t value = 0;
173 int i;
175 if (asLittleEndian) {
176 for (i = sizeof(int64_t) - 1; i >= 0; i--) {
177 value <<= 8;
178 value |= (int64_t)(unsigned char)buff[i];
181 else {
182 for (i = 0; i < (int) sizeof(int64_t); i++) {
183 value <<= 8;
184 value |= (int64_t)(unsigned char)buff[i];
188 pushInt64(L,value);
189 return 1;
192 WSLUA_CONSTRUCTOR Int64_decode(lua_State* L) {
193 /* Decodes an 8-byte Lua string, using the given endianness, into a new <<lua_class_Int64,`Int64`>> object. */
194 #define WSLUA_ARG_Int64_decode_STRING 1 /* The Lua string containing a binary 64-bit integer. */
195 #define WSLUA_OPTARG_Int64_decode_ENDIAN 2 /* If set to true then little-endian is used,
196 if false then big-endian; if missing or `nil`, native
197 host endian. */
198 bool asLittleEndian = IS_LITTLE_ENDIAN;
199 size_t len = 0;
200 const char *s = luaL_checklstring(L, WSLUA_ARG_Int64_decode_STRING, &len);
202 if (lua_gettop(L) >= WSLUA_OPTARG_Int64_decode_ENDIAN) {
203 if (lua_type(L,WSLUA_OPTARG_Int64_decode_ENDIAN) == LUA_TBOOLEAN)
204 asLittleEndian = lua_toboolean(L,WSLUA_OPTARG_Int64_decode_ENDIAN);
207 if (len == sizeof(int64_t)) {
208 Int64_unpack(L, s, asLittleEndian);
209 } else {
210 lua_pushnil(L);
213 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object created, or nil on failure. */
216 WSLUA_CONSTRUCTOR Int64_new(lua_State* L) {
217 /* Creates a <<lua_class_Int64,`Int64`>> object. */
218 #define WSLUA_OPTARG_Int64_new_VALUE 1 /* A number, <<lua_class_UInt64,`UInt64`>>, <<lua_class_Int64,`Int64`>>, or string of ASCII digits
219 to assign the value of the new <<lua_class_Int64,`Int64`>>. Default is 0. */
220 #define WSLUA_OPTARG_Int64_new_HIGHVALUE 2 /* If this is a number and the first argument was
221 a number, then the first will be treated as a
222 lower 32 bits, and this is the high-order 32
223 bit number. */
224 int64_t value = 0;
226 if (lua_gettop(L) >= 1) {
227 switch(lua_type(L, WSLUA_OPTARG_Int64_new_VALUE)) {
228 case LUA_TNUMBER:
229 value = wslua_toint64(L, WSLUA_OPTARG_Int64_new_VALUE);
230 if (lua_gettop(L) == 2 &&
231 lua_type(L, WSLUA_OPTARG_Int64_new_HIGHVALUE) == LUA_TNUMBER) {
232 int64_t h = wslua_toint64(L, WSLUA_OPTARG_Int64_new_HIGHVALUE);
233 value &= UINT64_C(0x00000000FFFFFFFF);
234 h <<= 32; h &= UINT64_C(0xFFFFFFFF00000000);
235 value += h;
237 break;
238 case LUA_TSTRING:
239 case LUA_TUSERDATA:
240 value = getInt64(L,WSLUA_OPTARG_Int64_new_VALUE);
241 break;
242 default:
243 WSLUA_OPTARG_ERROR(Int64_new,VALUE,"must be a number, UInt64, Int64, or string");
244 break;
248 pushInt64(L,value);
250 WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>> object. */
253 WSLUA_METAMETHOD Int64__call(lua_State* L) {
254 /* Creates a <<lua_class_Int64,`Int64`>> object. */
255 lua_remove(L,1); /* remove the table */
256 WSLUA_RETURN(Int64_new(L)); /* The new <<lua_class_Int64,`Int64`>> object. */
259 WSLUA_CONSTRUCTOR Int64_max(lua_State* L) {
260 /* 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. */
261 pushInt64(L, INT64_MAX);
262 WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>> object of the maximum value. */
265 WSLUA_CONSTRUCTOR Int64_min(lua_State* L) {
266 /* 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. */
267 pushInt64(L, INT64_MIN);
268 WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>> object of the minimum value. */
272 WSLUA_METHOD Int64_tonumber(lua_State* L) {
273 /* Returns a Lua number of the <<lua_class_Int64,`Int64`>> value. Note that this may lose precision. */
274 lua_pushnumber(L, (lua_Number)(checkInt64(L,1)));
275 WSLUA_RETURN(1); /* The Lua number. */
278 WSLUA_CONSTRUCTOR Int64_fromhex(lua_State* L) {
279 /* Creates an <<lua_class_Int64,`Int64`>> object from the given hexadecimal string. */
280 #define WSLUA_ARG_Int64_fromhex_HEX 1 /* The hex-ASCII Lua string. */
281 uint64_t result = 0;
282 size_t len = 0;
283 const char *s = luaL_checklstring(L,WSLUA_ARG_Int64_fromhex_HEX,&len);
285 if (len > 0) {
286 if (sscanf(s, "%" SCNx64, &result) != 1) {
287 return luaL_error(L, "Error decoding the passed-in hex string");
290 pushInt64(L,(int64_t)result);
291 WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>> object. */
294 WSLUA_METHOD Int64_tohex(lua_State* L) {
295 /* Returns a hexadecimal string of the <<lua_class_Int64,`Int64`>> value. */
296 #define WSLUA_OPTARG_Int64_tohex_NUMBYTES 2 /* The number of hex chars/nibbles to generate.
297 A negative value generates uppercase. Default is 16. */
298 int64_t b = getInt64(L,1);
299 lua_Integer n = luaL_optinteger(L, WSLUA_OPTARG_Int64_tohex_NUMBYTES, 16);
300 const char *hexdigits = "0123456789abcdef";
301 char buf[16];
302 lua_Integer i;
303 if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; }
304 if (n > 16) n = 16;
305 for (i = n-1; i >= 0; --i) { buf[i] = hexdigits[b & 15]; b >>= 4; }
306 lua_pushlstring(L, buf, (size_t)n);
307 WSLUA_RETURN(1); /* The string hex. */
310 WSLUA_METHOD Int64_higher(lua_State* L) {
311 /* Returns a Lua number of the higher 32 bits of the <<lua_class_Int64,`Int64`>> value. A negative <<lua_class_Int64,`Int64`>>
312 will return a negative Lua number.
314 int64_t num = getInt64(L,1);
315 int64_t b = num;
316 lua_Number n = 0;
317 if (b < 0) b = -b; /* masking/shifting negative int64 isn't working on some platforms */
318 b &= UINT64_C(0x7FFFFFFF00000000);
319 b >>= 32;
320 n = (lua_Number)(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF));
321 if (num < 0) n = -n;
322 lua_pushnumber(L,n);
323 WSLUA_RETURN(1); /* The Lua number. */
326 WSLUA_METHOD Int64_lower(lua_State* L) {
327 /* Returns a Lua number of the lower 32 bits of the <<lua_class_Int64,`Int64`>> value. This will always be positive. */
328 int64_t b = getInt64(L,1);
329 if (b < 0) b = -b; /* masking/shifting negative int64 isn't working on some platforms */
330 lua_pushnumber(L,(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF)));
331 WSLUA_RETURN(1); /* The Lua number. */
334 WSLUA_METAMETHOD Int64__tostring(lua_State* L) {
335 /* Converts the <<lua_class_Int64,`Int64`>> into a string of decimal digits. */
336 int64_t num = getInt64(L,1);
337 char s[LUATYPE64_STRING_SIZE];
338 if (snprintf(s, LUATYPE64_STRING_SIZE, "%" PRId64, num) < 0) {
339 return luaL_error(L, "Error writing Int64 to a string");
341 lua_pushstring(L,s);
342 WSLUA_RETURN(1); /* The Lua string. */
345 WSLUA_METAMETHOD Int64__unm(lua_State* L) {
346 /* Returns the negative of the <<lua_class_Int64,`Int64`>> as a new <<lua_class_Int64,`Int64`>>. */
347 pushInt64(L,-(getInt64(L,1)));
348 WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>>. */
351 #define WSLUA_MATH_OP_FUNC(obj,op) \
352 /* use the 'get' form so we can accept numbers as well */ \
353 obj num1 = get##obj(L,1); \
354 obj num2 = get##obj(L,2); \
355 push##obj(L,(num1) op (num2)); \
356 return 1
358 WSLUA_METAMETHOD Int64__add(lua_State* L) {
359 /* Adds two <<lua_class_Int64,`Int64`>> together and returns a new one. The value may wrapped. */
360 WSLUA_MATH_OP_FUNC(Int64,+);
363 WSLUA_METAMETHOD Int64__sub(lua_State* L) {
364 /* Subtracts two <<lua_class_Int64,`Int64`>> and returns a new one. The value may wrapped. */
365 WSLUA_MATH_OP_FUNC(Int64,-);
368 WSLUA_METAMETHOD Int64__mul(lua_State* L) {
369 /* Multiplies two <<lua_class_Int64,`Int64`>> and returns a new one. The value may truncated. */
370 WSLUA_MATH_OP_FUNC(Int64,*);
373 WSLUA_METAMETHOD Int64__div(lua_State* L) {
374 /* Divides two <<lua_class_Int64,`Int64`>> and returns a new one. Integer divide, no remainder.
375 Trying to divide by zero results in a Lua error.
377 Int64 num1 = getInt64(L,1);
378 Int64 num2 = getInt64(L,2);
379 if (num2 == 0) {
380 return luaL_error(L, "Trying to divide Int64 by zero");
382 pushInt64(L, num1 / num2);
383 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */
386 WSLUA_METAMETHOD Int64__mod(lua_State* L) {
387 /* Divides two <<lua_class_Int64,`Int64`>> and returns a new one of the remainder.
388 Trying to modulo by zero results in a Lua error.
390 Int64 num1 = getInt64(L,1);
391 Int64 num2 = getInt64(L,2);
392 if (num2 == 0) {
393 return luaL_error(L, "Trying to modulo Int64 by zero");
395 pushInt64(L, num1 % num2);
396 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */
399 WSLUA_METAMETHOD Int64__pow(lua_State* L) {
400 /* The first <<lua_class_Int64,`Int64`>> is taken to the power of the second <<lua_class_Int64,`Int64`>>, returning a new
401 one. This may truncate the value.
403 int64_t num1 = getInt64(L,1);
404 int64_t num2 = getInt64(L,2);
405 int64_t result;
406 if (num1 == 2) {
407 result = (num2 >= 8 * (int64_t) sizeof(int64_t)) ? 0 : ((int64_t)1 << num2);
409 else {
410 for (result = 1; num2 > 0; num2 >>= 1) {
411 if (num2 & 1) result *= num1;
412 num1 *= num1;
415 pushInt64(L,result);
416 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */
419 #define WSLUA_COMP_OP_FUNC(obj,op) \
420 obj num1 = get##obj(L,1); \
421 obj num2 = get##obj(L,2); \
422 lua_pushboolean(L,(num1) op (num2)); \
423 return 1
425 WSLUA_METAMETHOD Int64__eq(lua_State* L) {
426 /* Returns `true` if both <<lua_class_Int64,`Int64`>> are equal. */
427 WSLUA_COMP_OP_FUNC(Int64,==);
430 WSLUA_METAMETHOD Int64__lt(lua_State* L) {
431 /* Returns `true` if first <<lua_class_Int64,`Int64`>> is less than the second. */
432 WSLUA_COMP_OP_FUNC(Int64,<);
435 WSLUA_METAMETHOD Int64__le(lua_State* L) {
436 /* Returns `true` if the first <<lua_class_Int64,`Int64`>> is less than or equal to the second. */
437 WSLUA_COMP_OP_FUNC(Int64,<=);
440 WSLUA_METHOD Int64_bnot(lua_State* L) {
441 /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'not' operation. */
442 pushInt64(L,~(getInt64(L,1)));
443 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */
446 #define WSLUA_BIT_OP_FUNC(obj,op) \
447 int32_t i; \
448 obj num = get##obj(L,1); \
449 for (i = lua_gettop(L); i > 1; i--) { \
450 num op get##obj(L,i); \
452 push##obj(L,num); \
453 return 1
455 WSLUA_METHOD Int64_band(lua_State* L) {
456 /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'and' operation with the given number/`Int64`/`UInt64`.
457 Note that multiple arguments are allowed.
459 WSLUA_BIT_OP_FUNC(Int64,&=);
462 WSLUA_METHOD Int64_bor(lua_State* L) {
463 /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'or' operation, with the given number/`Int64`/`UInt64`.
464 Note that multiple arguments are allowed.
466 WSLUA_BIT_OP_FUNC(Int64,|=);
469 WSLUA_METHOD Int64_bxor(lua_State* L) {
470 /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'xor' operation, with the given number/`Int64`/`UInt64`.
471 Note that multiple arguments are allowed.
473 WSLUA_BIT_OP_FUNC(Int64,^=);
476 WSLUA_METHOD Int64_lshift(lua_State* L) {
477 /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise logical left-shift operation, by the given
478 number of bits.
480 #define WSLUA_ARG_Int64_lshift_NUMBITS 2 /* The number of bits to left-shift by. */
481 uint64_t b = (uint64_t) getInt64(L,1);
482 uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_lshift_NUMBITS);
483 pushInt64(L,(int64_t)(b << n));
484 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */
487 WSLUA_METHOD Int64_rshift(lua_State* L) {
488 /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise logical right-shift operation, by the
489 given number of bits.
491 #define WSLUA_ARG_Int64_rshift_NUMBITS 2 /* The number of bits to right-shift by. */
492 uint64_t b = (uint64_t) getInt64(L,1);
493 uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_rshift_NUMBITS);
494 pushInt64(L,(int64_t)(b >> n));
495 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */
498 WSLUA_METHOD Int64_arshift(lua_State* L) {
499 /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise arithmetic right-shift operation, by the
500 given number of bits.
502 #define WSLUA_ARG_Int64_arshift_NUMBITS 2 /* The number of bits to right-shift by. */
503 int64_t b = getInt64(L,1);
504 int32_t n = wslua_checkint32(L,WSLUA_ARG_Int64_arshift_NUMBITS);
505 pushInt64(L,(b >> n));
506 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */
509 WSLUA_METHOD Int64_rol(lua_State* L) {
510 /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise left rotation operation, by the given number of
511 bits (up to 63).
513 #define WSLUA_ARG_Int64_rol_NUMBITS 2 /* The number of bits to roll left by. */
514 uint64_t b = (uint64_t) getInt64(L,1);
515 uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_rol_NUMBITS);
516 pushInt64(L,(int64_t)((b << n) | (b >> (64-n))));
517 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */
520 WSLUA_METHOD Int64_ror(lua_State* L) {
521 /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise right rotation operation, by the given number of
522 bits (up to 63).
524 #define WSLUA_ARG_Int64_ror_NUMBITS 2 /* The number of bits to roll right by. */
525 uint64_t b = (uint64_t) getInt64(L,1);
526 uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_ror_NUMBITS);
527 pushInt64(L,(int64_t)((b << (64-n)) | (b >> n)));
528 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */
531 WSLUA_METHOD Int64_bswap(lua_State* L) {
532 /* Returns a <<lua_class_Int64,`Int64`>> of the bytes swapped. This can be used to convert little-endian
533 64-bit numbers to big-endian 64 bit numbers or vice versa.
535 uint64_t b = (uint64_t) getInt64(L,1);
536 uint64_t result = 0;
537 size_t i;
538 for (i = 0; i < sizeof(int64_t); i++) {
539 result <<= 8;
540 result |= (b & UINT64_C(0x00000000000000FF));
541 b >>= 8;
543 pushInt64(L,(int64_t)result);
544 WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */
547 /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META. */
548 static int Int64__gc(lua_State* L _U_) {
549 return 0;
552 WSLUA_METHODS Int64_methods[] = {
553 WSLUA_CLASS_FNREG(Int64,new),
554 WSLUA_CLASS_FNREG(Int64,max),
555 WSLUA_CLASS_FNREG(Int64,min),
556 WSLUA_CLASS_FNREG(Int64,tonumber),
557 WSLUA_CLASS_FNREG(Int64,fromhex),
558 WSLUA_CLASS_FNREG(Int64,tohex),
559 WSLUA_CLASS_FNREG(Int64,higher),
560 WSLUA_CLASS_FNREG(Int64,lower),
561 WSLUA_CLASS_FNREG(Int64,encode),
562 WSLUA_CLASS_FNREG(Int64,decode),
563 WSLUA_CLASS_FNREG(Int64,bnot),
564 WSLUA_CLASS_FNREG(Int64,band),
565 WSLUA_CLASS_FNREG(Int64,bor),
566 WSLUA_CLASS_FNREG(Int64,bxor),
567 WSLUA_CLASS_FNREG(Int64,lshift),
568 WSLUA_CLASS_FNREG(Int64,rshift),
569 WSLUA_CLASS_FNREG(Int64,arshift),
570 WSLUA_CLASS_FNREG(Int64,rol),
571 WSLUA_CLASS_FNREG(Int64,ror),
572 WSLUA_CLASS_FNREG(Int64,bswap),
573 { NULL, NULL }
576 WSLUA_META Int64_meta[] = {
577 WSLUA_CLASS_MTREG(Int64,tostring),
578 WSLUA_CLASS_MTREG(Int64,call),
579 WSLUA_CLASS_MTREG(wslua,concat),
580 WSLUA_CLASS_MTREG(Int64,unm),
581 WSLUA_CLASS_MTREG(Int64,add),
582 WSLUA_CLASS_MTREG(Int64,sub),
583 WSLUA_CLASS_MTREG(Int64,mul),
584 WSLUA_CLASS_MTREG(Int64,div),
585 WSLUA_CLASS_MTREG(Int64,mod),
586 WSLUA_CLASS_MTREG(Int64,pow),
587 WSLUA_CLASS_MTREG(Int64,eq),
588 WSLUA_CLASS_MTREG(Int64,lt),
589 WSLUA_CLASS_MTREG(Int64,le),
590 { NULL, NULL }
593 LUALIB_API int Int64_register(lua_State* L) {
594 WSLUA_REGISTER_CLASS(Int64);
595 return 0;
600 WSLUA_CLASS_DEFINE_BASE(UInt64,NOP,0);
602 <<lua_class_UInt64,`UInt64`>> represents a 64 bit unsigned integer, similar to <<lua_class_Int64,`Int64`>>.
604 Note the caveats <<lua_module_Int64,listed above>>.
607 /* A checkUInt64 but that also auto-converts numbers, strings, and <<lua_class_Int64,`Int64`>> to a uint64_t. */
608 uint64_t getUInt64(lua_State *L, int i)
610 char *end = NULL;
611 (void) end;
612 switch (lua_type(L,i))
614 case LUA_TNUMBER:
615 return wslua_checkuint64(L,i);
616 case LUA_TSTRING:
617 return g_ascii_strtoull(luaL_checkstring(L,i), &end, 0);
618 case LUA_TUSERDATA:
619 if (isInt64(L, i)) {
620 return (UInt64) toInt64(L, i);
622 /* fall through */
623 default:
624 return checkUInt64(L,i);
628 /* Encodes <<lua_class_UInt64,`UInt64`>> userdata into Lua string struct with given endianness */
629 void UInt64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian) {
630 uint64_t value = checkUInt64(L,idx);
631 int8_t buff[sizeof(uint64_t)];
633 if (asLittleEndian) {
634 unsigned i;
635 for (i = 0; i < sizeof(uint64_t); i++) {
636 buff[i] = (value & 0xff);
637 value >>= 8;
640 else {
641 int i;
642 for (i = sizeof(uint64_t) - 1; i >= 0; i--) {
643 buff[i] = (value & 0xff);
644 value >>= 8;
647 luaL_addlstring(b, (char*)buff, sizeof(uint64_t));
650 WSLUA_METHOD UInt64_encode(lua_State* L) {
651 /* Encodes the <<lua_class_UInt64,`UInt64`>> number into an 8-byte Lua binary string, using given endianness. */
652 #define WSLUA_OPTARG_UInt64_encode_ENDIAN 2 /* If set to true then little-endian is used,
653 if false then big-endian; if missing or `nil`,
654 native host endian. */
655 luaL_Buffer b;
656 bool asLittleEndian = IS_LITTLE_ENDIAN;
658 if (lua_gettop(L) >= 2) {
659 if (lua_type(L,2) == LUA_TBOOLEAN)
660 asLittleEndian = lua_toboolean(L,2);
663 luaL_buffinit(L, &b);
665 UInt64_pack(L, &b, 1, asLittleEndian);
667 luaL_pushresult(&b);
668 WSLUA_RETURN(1); /* The Lua binary string. */
671 /* Decodes from string buffer struct into <<lua_class_UInt64,`UInt64`>> userdata, with given endianness. */
672 int UInt64_unpack(lua_State* L, const char *buff, bool asLittleEndian) {
673 uint64_t value = 0;
674 int i;
676 if (asLittleEndian) {
677 for (i = sizeof(uint64_t) - 1; i >= 0; i--) {
678 value <<= 8;
679 value |= (uint64_t)(unsigned char)buff[i];
682 else {
683 for (i = 0; i < (int) sizeof(uint64_t); i++) {
684 value <<= 8;
685 value |= (uint64_t)(unsigned char)buff[i];
689 pushUInt64(L,value);
690 return 1;
693 WSLUA_CONSTRUCTOR UInt64_decode(lua_State* L) {
694 /* Decodes an 8-byte Lua binary string, using given endianness, into a new <<lua_class_UInt64,`UInt64`>> object. */
695 #define WSLUA_ARG_UInt64_decode_STRING 1 /* The Lua string containing a binary 64-bit integer. */
696 #define WSLUA_OPTARG_UInt64_decode_ENDIAN 2 /* If set to true then little-endian is used,
697 if false then big-endian; if missing or `nil`,
698 native host endian. */
699 bool asLittleEndian = IS_LITTLE_ENDIAN;
700 size_t len = 0;
701 const char *s = luaL_checklstring(L, WSLUA_ARG_UInt64_decode_STRING, &len);
703 if (lua_gettop(L) >= WSLUA_OPTARG_UInt64_decode_ENDIAN) {
704 if (lua_type(L,WSLUA_OPTARG_UInt64_decode_ENDIAN) == LUA_TBOOLEAN)
705 asLittleEndian = lua_toboolean(L,WSLUA_OPTARG_UInt64_decode_ENDIAN);
708 if (len == sizeof(uint64_t)) {
709 UInt64_unpack(L, s, asLittleEndian);
710 } else {
711 lua_pushnil(L);
714 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object created, or nil on failure. */
717 WSLUA_CONSTRUCTOR UInt64_new(lua_State* L) {
718 /* Creates a <<lua_class_UInt64,`UInt64`>> object. */
719 #define WSLUA_OPTARG_UInt64_new_VALUE 1 /* A number, <<lua_class_UInt64,`UInt64`>>, <<lua_class_Int64,`Int64`>>, or string of digits
720 to assign the value of the new <<lua_class_UInt64,`UInt64`>>. Default is 0. */
721 #define WSLUA_OPTARG_UInt64_new_HIGHVALUE 2 /* If this is a number and the first argument was
722 a number, then the first will be treated as a
723 lower 32 bits, and this is the high-order
724 32-bit number. */
725 uint64_t value = 0;
727 if (lua_gettop(L) >= 1) {
728 switch(lua_type(L, WSLUA_OPTARG_UInt64_new_VALUE)) {
729 case LUA_TNUMBER:
730 value = wslua_touint64(L, WSLUA_OPTARG_UInt64_new_VALUE);
731 if (lua_gettop(L) == 2 &&
732 lua_type(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE) == LUA_TNUMBER) {
733 uint64_t h = wslua_touint64(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE);
734 value &= UINT64_C(0x00000000FFFFFFFF);
735 h <<= 32; h &= UINT64_C(0xFFFFFFFF00000000);
736 value += h;
738 break;
739 case LUA_TSTRING:
740 case LUA_TUSERDATA:
741 value = getUInt64(L, WSLUA_OPTARG_UInt64_new_VALUE);
742 break;
743 default:
744 WSLUA_OPTARG_ERROR(UInt64_new,VALUE,"must be a number, UInt64, Int64, or string");
745 break;
749 pushUInt64(L,value);
751 WSLUA_RETURN(1); /* The new <<lua_class_UInt64,`UInt64`>> object. */
754 WSLUA_METAMETHOD UInt64__call(lua_State* L) {
755 /* Creates a <<lua_class_UInt64,`UInt64`>> object. */
756 lua_remove(L,1); /* remove the table */
757 WSLUA_RETURN(UInt64_new(L)); /* The new <<lua_class_UInt64,`UInt64`>> object. */
760 WSLUA_CONSTRUCTOR UInt64_max(lua_State* L) {
761 /* 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. */
762 pushUInt64(L,UINT64_MAX);
763 WSLUA_RETURN(1); /* The maximum value. */
766 WSLUA_CONSTRUCTOR UInt64_min(lua_State* L) {
767 /* Creates a <<lua_class_UInt64,`UInt64`>> of the minimum possible value. In other words, this should return an UInt64 object of the number 0. */
768 pushUInt64(L,0);
769 WSLUA_RETURN(1); /* The minimum value. */
772 WSLUA_METHOD UInt64_tonumber(lua_State* L) {
773 /* Returns a Lua number of the <<lua_class_UInt64,`UInt64`>> value. This may lose precision. */
774 lua_pushnumber(L,(lua_Number)(checkUInt64(L,1)));
775 WSLUA_RETURN(1); /* The Lua number. */
778 WSLUA_METAMETHOD UInt64__tostring(lua_State* L) {
779 /* Converts the <<lua_class_UInt64,`UInt64`>> into a string. */
780 uint64_t num = getUInt64(L,1);
781 char s[LUATYPE64_STRING_SIZE];
782 if (snprintf(s, LUATYPE64_STRING_SIZE, "%" PRIu64,(uint64_t)num) < 0) {
783 return luaL_error(L, "Error writing UInt64 to a string");
785 lua_pushstring(L,s);
786 WSLUA_RETURN(1); /* The Lua string. */
789 WSLUA_CONSTRUCTOR UInt64_fromhex(lua_State* L) {
790 /* Creates a <<lua_class_UInt64,`UInt64`>> object from the given hex string. */
791 #define WSLUA_ARG_UInt64_fromhex_HEX 1 /* The hex-ASCII Lua string. */
792 uint64_t result = 0;
793 size_t len = 0;
794 const char *s = luaL_checklstring(L,WSLUA_ARG_UInt64_fromhex_HEX,&len);
796 if (len > 0) {
797 if (sscanf(s, "%" SCNx64, &result) != 1) {
798 return luaL_error(L, "Error decoding the passed-in hex string");
801 pushUInt64(L,result);
802 WSLUA_RETURN(1); /* The new <<lua_class_UInt64,`UInt64`>> object. */
805 WSLUA_METHOD UInt64_tohex(lua_State* L) {
806 /* Returns a hex string of the <<lua_class_UInt64,`UInt64`>> value. */
807 #define WSLUA_OPTARG_UInt64_tohex_NUMBYTES 2 /* The number of hex-chars/nibbles to generate.
808 Negative means uppercase Default is 16. */
809 uint64_t b = getUInt64(L,1);
810 lua_Integer n = luaL_optinteger(L, WSLUA_OPTARG_UInt64_tohex_NUMBYTES, 16);
811 const char *hexdigits = "0123456789abcdef";
812 char buf[16];
813 lua_Integer i;
814 if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; }
815 if (n > 16) n = 16;
816 for (i = n-1; i >= 0; --i) { buf[i] = hexdigits[b & 15]; b >>= 4; }
817 lua_pushlstring(L, buf, (size_t)n);
818 WSLUA_RETURN(1); /* The string hex. */
821 WSLUA_METHOD UInt64_higher(lua_State* L) {
822 /* Returns a Lua number of the higher 32 bits of the <<lua_class_UInt64,`UInt64`>> value. */
823 uint64_t num = getUInt64(L,1);
824 uint64_t b = num;
825 lua_Number n = 0;
826 b &= UINT64_C(0xFFFFFFFF00000000);
827 b >>= 32;
828 n = (lua_Number)(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF));
829 lua_pushnumber(L,n);
830 WSLUA_RETURN(1); /* The Lua number. */
833 WSLUA_METHOD UInt64_lower(lua_State* L) {
834 /* Returns a Lua number of the lower 32 bits of the <<lua_class_UInt64,`UInt64`>> value. */
835 uint64_t b = getUInt64(L,1);
836 lua_pushnumber(L,(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF)));
837 WSLUA_RETURN(1); /* The Lua number. */
840 WSLUA_METAMETHOD UInt64__unm(lua_State* L) {
841 /* Returns the <<lua_class_UInt64,`UInt64`>> in a new <<lua_class_UInt64,`UInt64`>>, since unsigned integers can't be negated. */
842 pushUInt64(L,getUInt64(L,1));
843 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */
846 WSLUA_METAMETHOD UInt64__add(lua_State* L) {
847 /* Adds two <<lua_class_UInt64,`UInt64`>> together and returns a new one. This may wrap the value. */
848 WSLUA_MATH_OP_FUNC(UInt64,+);
851 WSLUA_METAMETHOD UInt64__sub(lua_State* L) {
852 /* Subtracts two <<lua_class_UInt64,`UInt64`>> and returns a new one. This may wrap the value. */
853 WSLUA_MATH_OP_FUNC(UInt64,-);
856 WSLUA_METAMETHOD UInt64__mul(lua_State* L) {
857 /* Multiplies two <<lua_class_UInt64,`UInt64`>> and returns a new one. This may truncate the value. */
858 WSLUA_MATH_OP_FUNC(UInt64,*);
861 WSLUA_METAMETHOD UInt64__div(lua_State* L) {
862 /* Divides two <<lua_class_UInt64,`UInt64`>> and returns a new one. Integer divide, no remainder.
863 Trying to divide by zero results in a Lua error.
865 UInt64 num1 = getUInt64(L,1);
866 UInt64 num2 = getUInt64(L,2);
867 if (num2 == 0) {
868 return luaL_error(L, "Trying to divide UInt64 by zero");
870 pushUInt64(L, num1 / num2);
871 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> result. */
874 WSLUA_METAMETHOD UInt64__mod(lua_State* L) {
875 /* Divides two <<lua_class_UInt64,`UInt64`>> and returns a new one of the remainder.
876 Trying to modulo by zero results in a Lua error.
878 UInt64 num1 = getUInt64(L,1);
879 UInt64 num2 = getUInt64(L,2);
880 if (num2 == 0) {
881 return luaL_error(L, "Trying to modulo UInt64 by zero");
883 pushUInt64(L, num1 % num2);
884 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> result. */
887 WSLUA_METAMETHOD UInt64__pow(lua_State* L) {
888 /* The first <<lua_class_UInt64,`UInt64`>> is taken to the power of the second <<lua_class_UInt64,`UInt64`>>/number,
889 returning a new one. This may truncate the value.
891 uint64_t num1 = getUInt64(L,1);
892 uint64_t num2 = getUInt64(L,2);
893 uint64_t result;
894 if (num1 == 2) {
895 result = (num2 >= 8 * (uint64_t) sizeof(uint64_t)) ? 0 : ((uint64_t)1 << num2);
897 else {
898 for (result = 1; num2 > 0; num2 >>= 1) {
899 if (num2 & 1) result *= num1;
900 num1 *= num1;
903 pushUInt64(L,result);
904 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */
907 WSLUA_METAMETHOD UInt64__eq(lua_State* L) {
908 /* Returns true if both <<lua_class_UInt64,`UInt64`>> are equal. */
909 WSLUA_COMP_OP_FUNC(UInt64,==);
912 WSLUA_METAMETHOD UInt64__lt(lua_State* L) {
913 /* Returns true if first <<lua_class_UInt64,`UInt64`>> is less than the second. */
914 WSLUA_COMP_OP_FUNC(UInt64,<);
917 WSLUA_METAMETHOD UInt64__le(lua_State* L) {
918 /* Returns true if first <<lua_class_UInt64,`UInt64`>> is less than or equal to the second. */
919 WSLUA_COMP_OP_FUNC(UInt64,<=);
922 WSLUA_METHOD UInt64_bnot(lua_State* L) {
923 /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'not' operation. */
924 pushUInt64(L,~(getUInt64(L,1)));
925 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */
928 WSLUA_METHOD UInt64_band(lua_State* L) {
929 /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'and' operation, with the given number/`Int64`/`UInt64`.
930 Note that multiple arguments are allowed.
932 WSLUA_BIT_OP_FUNC(UInt64,&=);
935 WSLUA_METHOD UInt64_bor(lua_State* L) {
936 /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'or' operation, with the given number/`Int64`/`UInt64`.
937 Note that multiple arguments are allowed.
939 WSLUA_BIT_OP_FUNC(UInt64,|=);
942 WSLUA_METHOD UInt64_bxor(lua_State* L) {
943 /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'xor' operation, with the given number/`Int64`/`UInt64`.
944 Note that multiple arguments are allowed.
946 WSLUA_BIT_OP_FUNC(UInt64,^=);
949 WSLUA_METHOD UInt64_lshift(lua_State* L) {
950 /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise logical left-shift operation, by the
951 given number of bits.
953 #define WSLUA_ARG_UInt64_lshift_NUMBITS 2 /* The number of bits to left-shift by. */
954 uint64_t b = getUInt64(L,1);
955 uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_lshift_NUMBITS);
956 pushUInt64(L,(b << n));
957 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */
960 WSLUA_METHOD UInt64_rshift(lua_State* L) {
961 /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise logical right-shift operation, by the
962 given number of bits.
964 #define WSLUA_ARG_UInt64_rshift_NUMBITS 2 /* The number of bits to right-shift by. */
965 uint64_t b = getUInt64(L,1);
966 uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_rshift_NUMBITS);
967 pushUInt64(L,(b >> n));
968 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */
971 WSLUA_METHOD UInt64_arshift(lua_State* L) {
972 /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise arithmetic right-shift operation, by the
973 given number of bits.
975 #define WSLUA_ARG_UInt64_arshift_NUMBITS 2 /* The number of bits to right-shift by. */
976 uint64_t b = getUInt64(L,1);
977 uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_arshift_NUMBITS);
978 pushUInt64(L,(b >> n));
979 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */
982 WSLUA_METHOD UInt64_rol(lua_State* L) {
983 /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise left rotation operation, by the
984 given number of bits (up to 63).
986 #define WSLUA_ARG_UInt64_rol_NUMBITS 2 /* The number of bits to roll left by. */
987 uint64_t b = getUInt64(L,1);
988 uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_rol_NUMBITS);
989 pushUInt64(L,((b << n) | (b >> (64-n))));
990 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */
993 WSLUA_METHOD UInt64_ror(lua_State* L) {
994 /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise right rotation operation, by the
995 given number of bits (up to 63).
997 #define WSLUA_ARG_UInt64_ror_NUMBITS 2 /* The number of bits to roll right by. */
998 uint64_t b = getUInt64(L,1);
999 uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_ror_NUMBITS);
1000 pushUInt64(L,((b << (64-n)) | (b >> n)));
1001 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */
1004 WSLUA_METHOD UInt64_bswap(lua_State* L) {
1005 /* Returns a <<lua_class_UInt64,`UInt64`>> of the bytes swapped. This can be used to convert little-endian
1006 64-bit numbers to big-endian 64 bit numbers or vice versa.
1008 uint64_t b = getUInt64(L,1);
1009 uint64_t result = 0;
1010 size_t i;
1011 for (i = 0; i < sizeof(uint64_t); i++) {
1012 result <<= 8;
1013 result |= (b & UINT64_C(0x00000000000000FF));
1014 b >>= 8;
1016 pushUInt64(L,result);
1017 WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */
1020 /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
1021 static int UInt64__gc(lua_State* L _U_) {
1022 return 0;
1025 WSLUA_METHODS UInt64_methods[] = {
1026 WSLUA_CLASS_FNREG(UInt64,new),
1027 WSLUA_CLASS_FNREG(UInt64,max),
1028 WSLUA_CLASS_FNREG(UInt64,min),
1029 WSLUA_CLASS_FNREG(UInt64,tonumber),
1030 WSLUA_CLASS_FNREG(UInt64,fromhex),
1031 WSLUA_CLASS_FNREG(UInt64,tohex),
1032 WSLUA_CLASS_FNREG(UInt64,higher),
1033 WSLUA_CLASS_FNREG(UInt64,lower),
1034 WSLUA_CLASS_FNREG(UInt64,encode),
1035 WSLUA_CLASS_FNREG(UInt64,decode),
1036 WSLUA_CLASS_FNREG(UInt64,bnot),
1037 WSLUA_CLASS_FNREG(UInt64,band),
1038 WSLUA_CLASS_FNREG(UInt64,bor),
1039 WSLUA_CLASS_FNREG(UInt64,bxor),
1040 WSLUA_CLASS_FNREG(UInt64,lshift),
1041 WSLUA_CLASS_FNREG(UInt64,rshift),
1042 WSLUA_CLASS_FNREG(UInt64,arshift),
1043 WSLUA_CLASS_FNREG(UInt64,rol),
1044 WSLUA_CLASS_FNREG(UInt64,ror),
1045 WSLUA_CLASS_FNREG(UInt64,bswap),
1046 { NULL, NULL }
1049 WSLUA_META UInt64_meta[] = {
1050 WSLUA_CLASS_MTREG(UInt64,tostring),
1051 WSLUA_CLASS_MTREG(UInt64,call),
1052 WSLUA_CLASS_MTREG(wslua,concat),
1053 WSLUA_CLASS_MTREG(UInt64,unm),
1054 WSLUA_CLASS_MTREG(UInt64,add),
1055 WSLUA_CLASS_MTREG(UInt64,sub),
1056 WSLUA_CLASS_MTREG(UInt64,mul),
1057 WSLUA_CLASS_MTREG(UInt64,div),
1058 WSLUA_CLASS_MTREG(UInt64,mod),
1059 WSLUA_CLASS_MTREG(UInt64,pow),
1060 WSLUA_CLASS_MTREG(UInt64,eq),
1061 WSLUA_CLASS_MTREG(UInt64,lt),
1062 WSLUA_CLASS_MTREG(UInt64,le),
1063 { NULL, NULL }
1066 LUALIB_API int UInt64_register(lua_State* L) {
1067 WSLUA_REGISTER_CLASS(UInt64);
1068 return 0;
1072 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1074 * Local variables:
1075 * c-basic-offset: 4
1076 * tab-width: 8
1077 * indent-tabs-mode: nil
1078 * End:
1080 * vi: set shiftwidth=4 tabstop=8 expandtab:
1081 * :indentSize=4:tabSize=8:noTabs=true: