Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Command Line Lua and Headless Emulation #526

Closed
JeffAlyanak opened this issue Nov 9, 2018 · 5 comments
Closed

Command Line Lua and Headless Emulation #526

JeffAlyanak opened this issue Nov 9, 2018 · 5 comments
Labels

Comments

@JeffAlyanak
Copy link

Caveat: I'm not sure how difficult this would be to implement as I haven't really dug into the codebase, but if it's doable I believe it would be of use to developers.

Feature Request

  • Command line option to run a Lua script
  • Headless operation option (no UI) for CLI Lua scripts

Details

I would love to see the ability to launch lua scripts from the command line and, in addition, run 'headless' emulation. I think these features would be a huge boon to developers and would really add to the already fantastic dev features.

I have found myself using Lua scripts during development to do run tests (using lua-unit) as it's a great way of verifying that subroutines function correctly in all cases, that inputs are always handled correctly, etc. Generally my tests will put the system into a known state, jump into a subroutine and then test the state upon the completion of the routine. This type of automated testing would benefit from a CLI option.

In addition, since there would be no need for manual I/O interaction, it would be excellent to allow these tests to run in a headless mode where the Mesen gui is not used at all and the lua script simply outputs to the terminal. This would allow for scripts or CI runners to easily run triggered tests upon building, commiting, etc.

@SourMesen
Copy link
Owner

This is actually already supported - I added this a while ago at another person's request but never added proper documentation for it.

Try this in a command prompt:
Mesen /testrunner myrom.nes myscript.lua

In the script, use emu.stop(exitcode) to return an exit code for the process. You can also specify a timeout in seconds with /timeout=100

The one thing you can't do is write output to the console - but it shouldn't be too hard to add if needed.

@JeffAlyanak
Copy link
Author

I'm not certain what it could be but that gives me a guaranteed critical error and mesen crashes immediately. Even if the lua script contains only the emu.stop, is completely empty or if I provide any of your example scripts.

The scripting works fine when run from the GUI but running them from the command line always provides this same error:

Critical error (UnexpectedError)
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  at Mesen.GUI.InteropEmu.SetFlafs(emulationFlags flags)
  at Mesen.GUI.Config.InputInfo.ApplyConfig()
  at Mesen.GUI.Config.Configuration.ApplyConfig()
  at Mesen.GUI.TestRunner.Run(String[] args)
  at Mesen.GUI.Program.Main(String[] args)

Is there a version aside from 0.9.7 that I should be using for this?

@SourMesen
Copy link
Owner

It's possible that the feature was broken in subsequent releases (nobody has actually been using this, afaik). You could try 0.9.4-0.9.6 to see if one of those work. I'll take a look at the crash when I get back home in a few weeks.

@JeffAlyanak
Copy link
Author

Thanks for the help. I'll see which version works as expected and then take a quick look at the relevant diffs, see if I can't spot something obvious.

@SourMesen SourMesen added the bug label Nov 20, 2018
@SourMesen
Copy link
Owner

The crash was caused by changes I did when adding support for VS Dual System.
It should be fixed as of 4e372fb, let me know if you still have issues with it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants