Thankyou 10yard. What you advise is close to what finally worked for me to both initiate rotation on launch and turn it back when exiting MAME. Getting Lua to execute a program in a layout .lay file cannot be done. Note this from a super helpful "cuavas" on the mamedev chat. "No it doesn't (support OS.Execute). The environment supplied to layout scripts is very restricted."
I was then directed to by cuavas that I could use a plugin and check the state of manager.machine.system.orientation. I think I may change it to checking ROM orientation. After looking at how they work from examples in the .\plugins directory I tried it and it works! This seems like a good way to control LEDs and lots of other external devices based on different MAME states in some cases if you don't want to use MAME Hooker.
Step 1: Make a folder under plugins with your new plugin name like autodisplayrotator.
Step 2: Create a plugin.json and init.lua file like the ones below using the ones in the \plugin\dummy folder as a template. Add the PowerShell or other external executables you want to run to the same plugin folder you created. (My attempts to get Lua to directly write to the serial port were unsuccessful.)
Step 3. Launch MAME and set your plugin to run on launch or add -plugin <your plugin name> to the command line. In my case I add -plugin autodisplayrotator to the MAME command line.
While I'm checking orientation and doing a different thing for start and stop based on manager.machine.system.orientation being set tp "rot270" (due to my vertical.ini file below.)You can do MANY other things with your plugin's init.lua in the \plugins\dummy folder. It allows you to run any code on start, stop, menu populate, and menu callback events. You can use the class references and what I will call pre-populated variables like manager.machine.system.orientation one I used. See:
https://docs.mamedev.org/techspecs/luareference.html?highlight=manager%20machine%20system%20orientation My plugin.jason folder in .\plugins\autodisplayrotator
{
"plugin": {
"name": "autodisplayrotator",
"description": "screen rotating plugin",
"version": "0.0.1",
"author": "David von Arb",
"type": "plugin",
"start": "false"
}
}
My init.lua file
-- license:BSD-3-Clause
-- copyright-holders:David
local exports = {}
exports.name = "autodisplayrotator"
exports.version = "0.0.1"
exports.description = "Rotate Display"
exports.license = "The BSD 3-Clause License"
exports.author = { name = "David" }
local autodisplayrotator = exports
function autodisplayrotator.startplugin()
emu.register\_start(function()
local screenrotation = manager.machine.system.orientation
print (screenrotation)
if (screenrotation == "rot270") or (screenrotation == "rot90")
then
print("Vertical game. Rotating...")
os.execute("powershell.exe -file vertical.ps1")
else
print("Horizontal game. Not Rotating...")
end
end)
emu.register\_stop(function()
local screenrotation = manager.machine.system.orientation
print (screenrotation)
if (screenrotation == "rot270") or (screenrotation == "rot90")
then
print ("Vertical game. Rotating back...")
os.execute("powershell.exe -file horizontal.ps1")
else
print("Horizontal game. No need to rotate back.")
end
end)
end
end exports