pd-rs / crankstart

A barely functional, wildly incomplete and basically undocumented Rust crate whose aim is to let you write Games for the Playdate handheld gaming system in Rust.
MIT License
235 stars 24 forks source link

A game built without `--device` running on device tries to run the Lua `playdate.update` #74

Open paulyoung opened 1 year ago

paulyoung commented 1 year ago

I’m not sure if this is a bug but it might be worth documenting if not.

I made a PR with some changes that allow interacting with the Lua runtime. I had to define an empty main.lua file and add the resulting main.pdz file to assets in Crank.toml or I got an error about main.pdz being missing when running in the simulator, but otherwise everything worked great.

(I’m now wondering if that’s even necessary if I build with --device and will try that later, see below)

As explained in this dev forum post; if I build with crank build and then upload via the simulator, something tries to call playdate.update in Lua. This obviously doesn’t exist, but if I define it in main.lua the function gets called.

If I build with crank build --device and upload to device via the simulator, my Rust update function gets called.

For what it’s worth, I’m uploading to device via the simulator because crank run --device hangs (https://github.com/pd-rs/crankstart/issues/41#issuecomment-1763471714)

paulyoung commented 1 year ago

I suppose this may actually belong in the crank repo, but I'll follow up here anyway.


I had to define an empty main.lua file and add the resulting main.pdz file to assets in Crank.toml or I got an error about main.pdz being missing when running in the simulator, but otherwise everything worked great.

(I’m now wondering if that’s even necessary if I build with --device and will try that later, see below)

I just tried this and it is necessary. --device makes no difference.


As explained in this dev forum post; if I build with crank build and then upload via the simulator, something tries to call playdate.update in Lua. This obviously doesn’t exist, but if I define it in main.lua the function gets called.

If I build with crank build --device and upload to device via the simulator, my Rust update function gets called.

The opposite appears to be true as well. If I do crank build --device and open the resulting .pdx in the simulator, I get a no such function 'update' error because something is trying to run a Lua playdate.update function. If I go to Device > Upload Game to Device the Rust update function runs on the device and things work as expected.