C API: get number of bitmaps in LCDBitmapTable

I'm loading animation steps into an LCDBitmapTable, and I would prefer not to hard code the number of animation steps in the program, but rather get the number of frames form the table itself, for example:

int playdate->graphics->getTableCount(LCDBitmapTable* table);

This is a very hacky way of doing it, but according to the docs getTableBitmap returns NULL if the index is out of bounds. So you could do something like this to get the number of bitmaps in the table:

int getTableCount(LCDBitmapTable* table) {
  int count = 0;
  while(playdate->graphics->getTableBitmap(table, count) != NULL) count++;

  return count;

I tested it out and it seems to work fine. I probably wouldn't be calling it every frame or anything, but it's good enough for caching the value after loading the table.

The LCDBitmapTable type is declared as a struct, but the struct itself doesn't appear in any of the .h files. I found references to it in the ELF file, but I'm not totally clear on how that works. I also saw an undocumented function LCDBitmapTable_size() in there, but I don't recommend using it because it's probably subject to change.

That's the usual way to implement private structs in C, so you can change the struct without breaking user code.

Thanks, but I agree that using private functions is not a good idea.

Oof. That was a dumb oversight. The struct has the count as an unsigned 16-bit int at the very start, and since it matches the file format it shouldn't ever change. So until we get proper API for that, count = *(uint16_t*)table; should work. :sweat_smile: