Feature request: add a `userdata` argument to `setSerialMessageCallback`

This is a feature request to change setSerialMessageCallback from:

void playdate->system->setSerialMessageCallback(void (*callback)(const char* data));

to:

void playdate->system->setSerialMessageCallback(void (*callback)(const char* data, void* userdata), void* userdata);

My specific motivation for this is that it would allow writing a more idiomatic Rust binding, like this one for playdate->file->listfiles: playdate/api/fs/src/lib.rs at de8d14cf9b1e689bfed610d9dff60cf0bc452e74 · boozook/playdate · GitHub

As for general motivation, all of the other callbacks have a userdata argument (as far as I know) which effectively allows us to access state from within the callback.

@fzzr does this make sense to you?

@dave, tagging you since I think you mentioned that you implemented this.

Thanks!

1 Like

That's could be great if possible, especially without extra overhead.
Yup, we're storing state or rust-call-abi-fn callback in the userdata. This is a less-overhead way to do it, I suppose.
Anyway we are storing our callbacks in the heap, so that is "plus one deref" for "get/store real userdata" or rarely used ops like "change callback" or "call callback by myself" for example.

My thoughts shortly is - could be great to have userdata absolutely everywhere where it possible and without extra overhead preferably.

1 Like