Testing SDK version from C or Lua

Is there any way to conditionally build or execute code based on the SDK version used?

I've looked for a version #define in the headers but maybe I've missed it...

At compile time, there doesn't appear to be any way to determine the SDK version from the API.

The next best thing is defining a custom symbol in the build command. Something like this:

$(OBJDIR)/pdex.elf: $(OBJS) $(LDSCRIPT)
	$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@ -D PD_SDK_1_13_1B1

And in the C code

#ifdef PD_SDK_1_13_1B1

Finally, for each build command that invokes a different version of the SDK, you define a different symbol.

That's not super useful if the #define is not done in the SDK itself though. :grinning:

The point of this would be to automatically compile different code based on the version of the SDK being used.

In Lua there's playdate.metadata.pdxversion, which is the SDK version the game was compiled with, and playdate.systemInfo.pdxversion, which is the SDK version the game is running under. We don't have matching C functions right now, but I'm filing that.

One thing about pdxversion that we might want to change is that we only bump it up on API changes, which since we're using semantic versioning means the last two digits will always be 00 and you can't tell which patch version the game is running under. It makes sense that systemInfo.pdxversion should include the patch version so your game knows, e.g., whether to use a workaround for a bug that existed in 1.x.1 but was fixed in 1.x.2.

4 Likes

We don't have matching C functions right now, but I'm filing that.

Sweet! thank you!

I'm going to request that the SDK version is exposed via #define rather than a function call. It's easy to turn a symbol into something like a string of display text, but it's not possible to do conditional compilation on function return values.

1 Like

It looks like pdxversion isn't documented?