mgba icon indicating copy to clipboard operation
mgba copied to clipboard

Python support for scripting

Open dvruette opened this issue 1 year ago • 4 comments

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?

dvruette avatar Oct 17 '23 08:10 dvruette

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.

endrift avatar Nov 06 '23 02:11 endrift

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:

  • Interacting with the emulator programmatically
  • Running in headless mode
  • Stepping through the simulation frame-by-frame

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?

dvruette avatar Nov 07 '23 12:11 dvruette

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.

endrift avatar Nov 08 '23 03:11 endrift

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.

GeekTeaa avatar Feb 24 '24 04:02 GeekTeaa