playdate->lua->registerClass lua_val crashes on device

Hi folks!

I have an odd bug which I assume may be a C compiler/linker thing, but which has really stumped me. I have code that calls playdate->lua->registerClass that works on the simulator but crashes on the device. More specifically it worked great on both the simulator and device when the code was all in main.c. But when I moved it to it's own file, it still works on the simulator but crashes the device.

The crash in playdate->lua->registerClass class function only occurs when you are passing something to the third parameter (const lua_val* vals). This is used when you want to create constants as class attributes for lua.

I created a minimal test case in this repo:

There are two branches and two builds.
-- built from works branch (works on device)
-- built from main branch (crashes on device) (3.5 KB) (3.2 KB)

This PR shows the changes between them.

My device (v1 playdate) is running firmware 2.1.0-beta1.
Built with Playdate SDK 2.0.3 and PlaydateSDK 2.1.0-beta1 on MacOS 13.6 (Intel).

I was getting one of the following errors (sometimes 229, 225 or 33):

invalid constant type in lua_registerClass: 229

But at somepoint it stopped letting me "hit b to the see the error" and now it just throws an e0 error and now only gives "hit a to restart" with no option to see the error. :person_shrugging: