Trivial Object improvements

It'd be nice if the chained form of class creation in the sdk docs example returned a reference to the class.

class('MySprite').extends(playdate.graphics.sprite)

Currently .extends(Parent) does not return anything. It'd be sweet if at the end of __NewClass.extends(Parent) in Object.lua you could add a return Child. I've patched my locally copy to do this.

Then I can:

MySprite = class("MySprite").extends("playdate.graphics.sprite")

It would also make private classes a one liner:

local MySprite = class("MySprite", nil, nil).extends("playdate.graphics.sprite")
2 Likes

I came up with a silly one liner partial workaround. Use:

MySprite = class('MySprite').extends(playdate.graphics.sprite) or MySprite

Instead of:

class('MySprite').extends(playdate.graphics.sprite)

The latter operates implicitly by injecting A into the global namespace.
The former includes an explicit global assignment.

It's an awkward no-op, but it's enough for static analysis tools to keep track of where MySprite gets created.

Relatedly, I improved playdate-luacats to have proper type annotations for the APIs provided by object.lua. See: notpeter/playdate-luacats - v2.1.0-luacats7.

1 Like