| 125 | } |
| 126 | |
| 127 | static int bit_tohex(lua_State *L) |
| 128 | { |
| 129 | UBits b = barg(L, 1); |
| 130 | SBits n = lua_isnone(L, 2) ? 8 : (SBits)barg(L, 2); |
| 131 | const char *hexdigits = "0123456789abcdef"; |
| 132 | char buf[8]; |
| 133 | int i; |
| 134 | if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; } |
| 135 | if (n > 8) n = 8; |
| 136 | for (i = (int)n; --i >= 0; ) { buf[i] = hexdigits[b & 15]; b >>= 4; } |
| 137 | lua_pushlstring(L, buf, (size_t)n); |
| 138 | return 1; |
| 139 | } |
| 140 | |
| 141 | static const struct luaL_Reg bit_funcs[] = { |
| 142 | { "tobit", bit_tobit }, |
nothing calls this directly
no test coverage detected