Lua Catalog API accepts negative number

On any platform, the Catalog scoreboard API on the SDK accepts to call addScore() with a negative score value.

Instead of accepting it and wrapping around the negative number around a very high 32bits integer, the SDK should throw an error the same way that it would throw an error for an invalid scoreboard name.

Here’s a typical piece of

local score = -1

playdate.scoreboards.addScore(scoreboard, score, 
   function (status, result)
       if status.code == "ERROR" then
           print(status.message)
       end
end)

For instance, this piece of code should definitely throw an error instead of submitting something like 4,294,967,295.

This probably also happen on the C SDK but I didn’t test this.

2 Likes

C SDK is not concerned by this issue because the score is a 32 bit unsigned integer so you can't pass negative values.

1 Like

Seems appropriate enough… but in Lua I can definitely tell you that you can send negative numbers and they even display as such in the Lua UI I have but if you take a look at those scores (see screenshot just below) you clearly understand the problem :

though at the default cmake warning levels it’ll happily and silently cast an int to a uint without any warnings, so it’s still possible.

no but the real problem I have is that the Lua SDK doesn’t throw an error when you call addScore with a negative number… I’d prefer if it threw an error instead of accepting a 4 Billion score

3 Likes

(Duplicating our discord chat for the general public :smile:)

I've got this filed for 3.1, ftr. Since the function doesn't currently have a return value indicating an immediate error I'll have it send the error to the callback. Thanks for catching this!

2 Likes