diff options
Diffstat (limited to 'plugins/layout')
-rw-r--r-- | plugins/layout/init.lua | 70 | ||||
-rw-r--r-- | plugins/layout/plugin.json | 2 |
2 files changed, 54 insertions, 18 deletions
diff --git a/plugins/layout/init.lua b/plugins/layout/init.lua index 8301167633e..f3b1094ef55 100644 --- a/plugins/layout/init.lua +++ b/plugins/layout/init.lua @@ -2,33 +2,67 @@ -- copyright-holders:Carl -- Layout scripts should return a table and a string. The table can have two optional keys reset and frame -- which have functions for values called on reset and frame draw respectively and the string is a unique name. -local exports = {} -exports.name = "layout" -exports.version = "0.0.1" -exports.description = "Layout helper plugin" -exports.license = "The BSD 3-Clause License" -exports.author = { name = "Carl" } +local exports = { + name = "layout", + version = "0.0.1", + description = "Layout helper plugin", + license = "BSD-3-Clause", + author = { name = "Carl" } } local layout = exports +local frame_subscription, stop_subscription + function layout.startplugin() local scripts = {} - local function prepare_layout(script) - local env = { machine = manager:machine(), pairs = pairs, ipairs = ipairs, - table = { insert = table.insert, remove = table.remove } } + local function prepare_layout(file, script) + local env = { + machine = manager.machine, + emu = { + device_enumerator = emu.device_enumerator, + palette_enumerator = emu.palette_enumerator, + screen_enumerator = emu.screen_enumerator, + cassette_enumerator = emu.cassette_enumerator, + image_enumerator = emu.image_enumerator, + slot_enumerator = emu.slot_enumerator, + attotime = emu.attotime, + render_bounds = emu.render_bounds, + render_color = emu.render_color, + bitmap_ind8 = emu.bitmap_ind8, + bitmap_ind16 = emu.bitmap_ind16, + bitmap_ind32 = emu.bitmap_ind32, + bitmap_ind64 = emu.bitmap_ind64, + bitmap_yuy16 = emu.bitmap_yuy16, + bitmap_rgb32 = emu.bitmap_rgb32, + bitmap_argb32 = emu.bitmap_argb32, + print_verbose = emu.print_verbose, + print_error = emu.print_error, + print_warning = emu.print_warning, + print_info = emu.print_info, + print_debug = emu.print_debug }, + file = file, + math = math, + print = print, + pairs = pairs, + ipairs = ipairs, + string = string, + tonumber = tonumber, + tostring = tostring, + table = table } local script, err = load(script, script, "t", env) if not script then - emu.print_verbose("error loading layout script " .. err) + emu.print_warning("error loading layout script " .. err) return end - local name - script, name = script() - scripts[name] = script + local hooks = script() + if hooks ~= nil then + table.insert(scripts, hooks) + end end emu.register_callback(prepare_layout, "layout") - emu.register_frame(function() - if manager:machine().paused then + frame_subscription = emu.add_machine_frame_notifier(function () + if manager.machine.paused then return end for num, scr in pairs(scripts) do @@ -37,14 +71,16 @@ function layout.startplugin() end end end) - emu.register_start(function() + emu.register_prestart(function () for num, scr in pairs(scripts) do if scr.reset then scr.reset() end end end) - emu.register_stop(function() scripts = {} end) + stop_subscription = emu.add_machine_stop_notifier(function () + scripts = {} + end) end return exports diff --git a/plugins/layout/plugin.json b/plugins/layout/plugin.json index 996e09d6a07..706464157b9 100644 --- a/plugins/layout/plugin.json +++ b/plugins/layout/plugin.json @@ -5,6 +5,6 @@ "version": "0.0.1", "author": "Carl", "type": "plugin", - "start": "false" + "start": "true" } } |