MAME Lua Plugins

MAMEDev recently applied a patch of mine (thanks to Miodrag) to MAME 0180. It exposes render_target::view_name() so my showcp plugin can check the name of the view before toggling.

Here is the new script:

-- license:BSD-3-Clause
-- copyright-holders:Ben Baker
local exports = {}
exports.name = "showcp"
exports.version = "0.0.2"
exports.description = "ShowCP plugin"
exports.license = "The BSD 3-Clause License"
exports.author = { name = "Ben Baker" }

local showcp = exports

function showcp.startplugin()
    emu.register_pause(function()
        local target = manager:machine():render():targets()[0]

        if target:view_name(1) == "Show CP" then
            target.view = 1
        end
    end)

    emu.register_resume(function()
        local target = manager:machine():render():targets()[0]

        if target:view_name(1) == "Show CP" then
            target.view = 0
        end
    end)
end

return exports

You can see based on this 1942.lay file how the view name is referred in the xml:

<?xml version="1.0"?>
<mamelayout version="2">
  <element name="CP">
    <image file="CP.png" />
  </element>
  <element name="Bezel">
    <image file="Bezel.png" />
  </element>
  <view name="Hide CP">
    <screen index="0">
      <bounds left="140" top="0" right="500" bottom="480" />
    </screen>
    <bezel element="Bezel">
      <bounds left="0" top="0" right="640" bottom="480" />
    </bezel>
  </view>
  <view name="Show CP">
    <screen index="0">
      <bounds left="140" top="0" right="500" bottom="480" />
    </screen>
    <bezel element="Bezel">
      <bounds left="0" top="0" right="640" bottom="480" />
    </bezel>
    <bezel element="CP">
      <bounds left="0" top="0" right="640" bottom="480" />
    </bezel>
  </view>
</mamelayout>

showcp.zip