MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / barg

Function barg

deps/lua/src/lua_bit.c:57–91  ·  view source on GitHub ↗

Convert argument to bit type. */

Source from the content-addressed store, hash-verified

55
56/* Convert argument to bit type. */
57static UBits barg(lua_State *L, int idx)
58{
59 BitNum bn;
60 UBits b;
61#if LUA_VERSION_NUM < 502
62 bn.n = lua_tonumber(L, idx);
63#else
64 bn.n = luaL_checknumber(L, idx);
65#endif
66#if defined(LUA_NUMBER_DOUBLE)
67 bn.n += 6755399441055744.0; /* 2^52+2^51 */
68#ifdef SWAPPED_DOUBLE
69 b = (UBits)(bn.b >> 32);
70#else
71 b = (UBits)bn.b;
72#endif
73#elif defined(LUA_NUMBER_INT) || defined(LUA_NUMBER_LONG) || \
74 defined(LUA_NUMBER_LONGLONG) || defined(LUA_NUMBER_LONG_LONG) || \
75 defined(LUA_NUMBER_LLONG)
76 if (sizeof(UBits) == sizeof(lua_Number))
77 b = bn.b;
78 else
79 b = (UBits)(SBits)bn.n;
80#elif defined(LUA_NUMBER_FLOAT)
81#error "A 'float' lua_Number type is incompatible with this library"
82#else
83#error "Unknown number type, check LUA_NUMBER_* in luaconf.h"
84#endif
85#if LUA_VERSION_NUM < 502
86 if (b == 0 && !lua_isnumber(L, idx)) {
87 luaL_typerror(L, idx, "number");
88 }
89#endif
90 return b;
91}
92
93/* Return bit type. */
94#define BRET(b) lua_pushnumber(L, (lua_Number)(SBits)(b)); return 1;

Callers 6

bit_tobitFunction · 0.85
bit_bnotFunction · 0.85
lua_bit.cFile · 0.85
bit_bswapFunction · 0.85
bit_tohexFunction · 0.85
luaopen_bitFunction · 0.85

Calls 4

lua_tonumberFunction · 0.85
luaL_checknumberFunction · 0.85
lua_isnumberFunction · 0.85
luaL_typerrorFunction · 0.85

Tested by

no test coverage detected