Convert argument to bit type. */
| 55 | |
| 56 | /* Convert argument to bit type. */ |
| 57 | static 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; |
no test coverage detected