| 153 | } flags { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 154 | |
| 155 | int main() { |
| 156 | std::cout << "=== usertype_bitfields ===" << std::endl; |
| 157 | #ifdef __MINGW32__ |
| 158 | std::cout << "MinGW Detected, packing structs is broken in " |
| 159 | "MinGW and this test may fail" |
| 160 | << std::endl; |
| 161 | #endif |
| 162 | sol::state lua; |
| 163 | lua.open_libraries(); |
| 164 | |
| 165 | lua.new_usertype<flags_t>("flags_t", |
| 166 | "C", |
| 167 | sol::property(itsy_bitsy::read<flags_t, 0>, |
| 168 | itsy_bitsy::write<flags_t, 0>), |
| 169 | "N", |
| 170 | sol::property(itsy_bitsy::read<flags_t, 1>, |
| 171 | itsy_bitsy::write<flags_t, 1>), |
| 172 | "D", |
| 173 | sol::property(itsy_bitsy::read<flags_t, 8, 14>, |
| 174 | itsy_bitsy::write<flags_t, 8, 14>)); |
| 175 | |
| 176 | lua["f"] = std::ref(flags); |
| 177 | |
| 178 | lua.script(R"( |
| 179 | print(f.C) |
| 180 | f.C = true; |
| 181 | print(f.C) |
| 182 | |
| 183 | print(f.N) |
| 184 | f.N = true; |
| 185 | print(f.N) |
| 186 | |
| 187 | print(f.D) |
| 188 | f.D = 0xDF; |
| 189 | print(f.D) |
| 190 | )"); |
| 191 | |
| 192 | bool C = flags.C; |
| 193 | bool N = flags.N; |
| 194 | uint16_t D = flags.D; |
| 195 | |
| 196 | std::cout << std::hex; |
| 197 | std::cout << "sizeof(flags): " << sizeof(flags) |
| 198 | << std::endl; |
| 199 | std::cout << "C: " << C << std::endl; |
| 200 | std::cout << "N: " << N << std::endl; |
| 201 | std::cout << "D: " << D << std::endl; |
| 202 | |
| 203 | SOL_ASSERT(C); |
| 204 | SOL_ASSERT(N); |
| 205 | SOL_ASSERT(D == 0xDF); |
| 206 | |
| 207 | std::cout << std::endl; |
| 208 | |
| 209 | return 0; |
| 210 | } |
nothing calls this directly
no test coverage detected