mgba-emu / mgba

mGBA Game Boy Advance Emulator
https://mgba.io/
Mozilla Public License 2.0
5.63k stars 770 forks source link

Python support for scripting #3048

Open dvruette opened 11 months ago

dvruette commented 11 months ago

I read somewhere that it's planned to add Python support for the scripting API, and I think that would be a great idea, unlocking GBA games to easily interface with the most popular ML/RL libraries. I'm willing to help implement this, but I'd need some pointers on where to get started and what needs to be implemented. Any hints?

endrift commented 10 months ago

This is gonna require rather deep interactions with the scripting subsystem. You can take a look at src/script/engines/lua.c to see how Lua is bound, but it's gonna be difficult to add Python. It is planned though.

dvruette commented 10 months ago

I'm taking a look at this now and I'm finding that the existing python bindings actually work quite well and pretty much do exactly what I'm looking for, including:

I also saw in #2773 that the python bindings are deprecated, so I was wondering what the reasoning was behind the decision? From what I can see (after having spent a minimal amount of time, so maybe I'm missing something), scripting works quite differently and interacts with the game in real time. For example, AFAICT it's not possible to run the game in headless mode and step through it using the script. Since the two features seem to serve different purposes, wouldn't it make sense to keep both?

endrift commented 10 months ago

The Python bindings are somewhat fragile and not extensible. I'm hoping to make a headless version that lets you configure and run emulation in a similar way and also supports multiple languages through the same binding subsystem. It's a lot less overhead to have one scripting system instead of two, too.

GeekTeaa commented 7 months ago

I'm actually doing a project right now to leverage the existing mgba python bindings in a RL AI application with some fair luck. I've created a dockerfile that starts from the Jammy Ubuntu build image and adds any of the required python packages to generate the bindings.

But, based on this post, this feature set will be deprecated (ideally) when 0.11.0 is released? Sounds like I don't want to leverage these in the short-term then.

Is there an active branch where this development is being worked on? I'm happy to contribute to this effort where I can. I'll take a look at lua.c in the mean time.