More people use COUNTOF;

This commit is contained in:
bjorn 2022-03-22 17:56:26 -07:00
parent 98e186af5b
commit b7527c3584
5 changed files with 6 additions and 6 deletions

View File

@ -628,7 +628,7 @@ static int l_lovrHeadsetGetHands(lua_State* L) {
int count = 0;
float position[4], orientation[4];
Device hands[] = { DEVICE_HAND_LEFT, DEVICE_HAND_RIGHT };
for (size_t i = 0; i < sizeof(hands) / sizeof(hands[0]); i++) {
for (size_t i = 0; i < COUNTOF(hands); i++) {
FOREACH_TRACKING_DRIVER(driver) {
if (driver->getPose(hands[i], position, orientation)) {
luax_pushenum(L, Device, hands[i]);
@ -706,7 +706,7 @@ int luaopen_lovr_headset(lua_State* L) {
for (int i = 0; i < n; i++) {
lua_rawgeti(L, -1, i + 1);
drivers[driverCount++] = luax_checkenum(L, -1, HeadsetDriver, NULL);
lovrAssert(driverCount < sizeof(drivers) / sizeof(drivers[0]), "Too many headset drivers specified in conf.lua");
lovrAssert(driverCount < COUNTOF(drivers), "Too many headset drivers specified in conf.lua");
lua_pop(L, 1);
}
lua_pop(L, 1);

View File

@ -380,7 +380,7 @@ int luaopen_lovr_math(lua_State* L) {
lua_pushcfunction(L, l_lovrLightUserdata__index);
lua_setfield(L, -2, "__index");
const char* ops[] = { "__add", "__sub", "__mul", "__div", "__unm", "__len", "__tostring", "__newindex" };
for (size_t i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
for (size_t i = 0; i < COUNTOF(ops); i++) {
lua_pushstring(L, ops[i]);
lua_pushcclosure(L, l_lovrLightUserdataOp, 1);
lua_setfield(L, -2, ops[i]);

View File

@ -25,7 +25,7 @@ Joint* luax_checkjoint(lua_State* L, int index) {
hash64("SliderJoint", strlen("SliderJoint"))
};
for (size_t i = 0; i < sizeof(hashes) / sizeof(hashes[0]); i++) {
for (size_t i = 0; i < COUNTOF(hashes); i++) {
if (p->hash == hashes[i]) {
return p->object;
}

View File

@ -27,7 +27,7 @@ Shape* luax_checkshape(lua_State* L, int index) {
hash64("MeshShape", strlen("MeshShape")),
};
for (size_t i = 0; i < sizeof(hashes) / sizeof(hashes[0]); i++) {
for (size_t i = 0; i < COUNTOF(hashes); i++) {
if (p->hash == hashes[i]) {
return p->object;
}

View File

@ -238,7 +238,7 @@ bool lovrAudioInit(const char* spatializer, uint32_t sampleRate) {
result = ma_mutex_init(&state.lock);
lovrAssert(result == MA_SUCCESS, "Failed to create audio mutex");
for (size_t i = 0; i < sizeof(spatializers) / sizeof(spatializers[0]); i++) {
for (size_t i = 0; i < COUNTOF(spatializers); i++) {
if (spatializer && strcmp(spatializer, spatializers[i]->name)) {
continue;
}