Playdate SDK support for luacheck

I've started adding support for the Playdate SDK in luacheck. This can either be used from the command line or integrated in your editor, for example if you're using Nova it already has an extension for luacheck.

I made a fork of the project and included my current PR and also another one which adds support for compound operators. It works great here(tm) and I've ran it across most of the SDK sample code but I would love some help testing this further so if anyone has time that would be awesome.

You'll need something like this in a .luacheckrc file:

std = "lua54+playdate"
operators = {"+=", "-=", "*=", "/="}

A couple of caveats so far, if you use OO support provided by the SDK you'll need to a comment like this to quiet a warning for declarations:

-- luacheck: globals Scroller
class('Scroller').extends(Object)

and a comment like this if a member function doesn't use self (which, of course, means it probably doesn't need to be a member function :slight_smile: )

function Scroller:find_char_index(character) -- luacheck: ignore self

I've made the decision to no include member methods right now. They can't be checked by luacheck when they are being used with the : syntax (for example myNineSlice:getSize()) and I my thinking right now is that it could help spot incorrect uses like playdate.graphics.nineSlice.getSize().

Let me know what you guys think about this.

6 Likes

A quick update on this, the playdate sdk support is now included in the main branch for luacheck although it hasn't been included in a release yet.

Compound operator support is still in a PR at this point. I've been using both in my daily development in Nova and it's a game changer.

2 Likes

Wow this is super helpful, especially for people new to Lua like myself. Thanks for this!

Took me a while to figure out how to install development versions through luarocks, but if it saves anyone else time I used:

luarocks install --server=https://luarocks.org/dev luacheck dev-1

It's working great for me so far! The only other caveat I found is it will also show a warning (143) if you try to call a method directly from playdate (like playdate.getCrankTicks()). I found it easiest just to declare playdate as global in the .luacheckrc file.

std = "lua54+playdate+project"
stds.project = {
   read_globals = {"playdate"}
}
1 Like
std = "lua54+playdate+project"
stds.project = {
   read_globals = {"playdate"}
}

Actually, when you do that you make the entire playdate global 'fair game' so you're actually overriding the playdate support in luacheck :smile:

So 143 is Accessing an undefined field of a global variable. which means somehow the file giving you that warning is not using the correct .luacheckrc file or it's not using the right version of luacheck, otherwise anything like playdate.setCrankSoundsDisabled(true) would not provide a warning since it should be already taken care of in std = "lua54+playdate"

Let's try and figure out what is going on here to make sure it's not a bug on my end. What platform are you on? When you do luacheck -h from the command line do you see the playdate option for --std? -> playdate - globals added by the Playdate SDK;

1 Like

Oh I see, I'll remove that then! Also I checked some more, and my bad playdate.getCrankTicks() is the only method call in my project returning that 143 warning (this is what happens when I try to diagnose issues at 2am :sweat_smile:). I can access other playdate methods just fine! I think getCrankTicks() might just be missing from the standard.

But just in case, yes luacheck -h shows the playdate option and I am on macOS 12 (x86).

Yay! You found an omission on my end. Thank you! I'm adding it to the next PR I'll submit to luacheck along with a couple of other fixes.

In the meantime, I've added those changed to my fork in case you want them right away.

No problem! And yeah I'll probably switch over to your fork just for the compound operators.

Also do you think it is worth adding support for the Pulp audio runtime? It's not technically part of the SDK, but is from Panic as well. It's got a pretty simple API:

pulp = {
	audio = {
		kPlayLoop = (boolean),
		kPlayOnce = (boolean),
		init = (function),
		update = (function),
		playSound = (function),
		playSong = (function),
		stopSong = (function),
		setBpm = (function),
	}
}

Also do you think it is worth adding support for the Pulp audio runtime?

Yeah that would be easy to do. Where is this documented?

Surprisingly I couldn’t find any documentation of the API! But you can download it by going to Pulp and clicking download bundle button next to audio runtime on the bottom right of the page:

image

Thanks! I'll take a look. In the meantime those fixes, including the one you found, are in the main branch of luacheck now.

1 Like

Support for the pulp audio API has been added to my testing-playdate branch. @SudoBun Do you have any projects you could test this on yourself?