summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author Vas Crabb <cuavas@users.noreply.github.com>2022-03-23 20:27:30 +1100
committer GitHub <noreply@github.com>2022-03-23 20:27:30 +1100
commite6588480c477a8132676abbbb32bfc42287d8c6d (patch)
treeb483f8b9e049a280f68ae7b0af9c57372676f5df /plugins
parentbb3f3e5abd7051ed371fe7fbdd0f49a56cc03f1f (diff)
Lua engine improvements (#9453)
Made auto-boot script errors and plugin bootstrap errors fatal. Run auto-boot scripts in a sandbox. Globals can be accessed, but not set. The sandbox is cleared on hard reset, but not on soft reset. Added (hopefully) useful to string metafunctions to device_t and address space that show short names and tags. Fixed issues in plugins that surface when strict type checking is enabled, as this means numbers and nil are not automatically converted to strings. Plugins should be tested with debug builds to check for this. Made save item read_block raise an error on invalid arguments rather than returning an empty string, and made it use luaL_buffer directly rather than using the helper wrapper. Changed some more function bindings to use set_function to avoid issues related to ThePhD/sol2#608, and got rid of some unnecessary lambda captures.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/autofire/autofire_menu.lua4
-rw-r--r--plugins/cheatfind/init.lua10
-rw-r--r--plugins/inputmacro/inputmacro_menu.lua24
-rw-r--r--plugins/timer/init.lua2
4 files changed, 20 insertions, 20 deletions
diff --git a/plugins/autofire/autofire_menu.lua b/plugins/autofire/autofire_menu.lua
index 5c87e27a63d..e2287ce2276 100644
--- a/plugins/autofire/autofire_menu.lua
+++ b/plugins/autofire/autofire_menu.lua
@@ -157,8 +157,8 @@ local function populate_configure_menu(menu)
configure_selection_save = #menu
end
table.insert(menu, {_p('plugin-autofire', 'Hotkey'), key_name, hotkey_poller and 'lr' or ''})
- table.insert(menu, {_p('plugin-autofire', 'On frames'), current_button.on_frames, current_button.on_frames > 1 and 'lr' or 'r'})
- table.insert(menu, {_p('plugin-autofire', 'Off frames'), current_button.off_frames, current_button.off_frames > 1 and 'lr' or 'r'})
+ table.insert(menu, {_p('plugin-autofire', 'On frames'), tostring(current_button.on_frames), current_button.on_frames > 1 and 'lr' or 'r'})
+ table.insert(menu, {_p('plugin-autofire', 'Off frames'), tostring(current_button.off_frames), current_button.off_frames > 1 and 'lr' or 'r'})
configure_menu_active = true
end
diff --git a/plugins/cheatfind/init.lua b/plugins/cheatfind/init.lua
index d565b31437f..96617e12fb6 100644
--- a/plugins/cheatfind/init.lua
+++ b/plugins/cheatfind/init.lua
@@ -351,7 +351,7 @@ function cheatfind.startplugin()
for num, func in ipairs(menu) do
local item, f = func()
if item then
- menu_list[#menu_list + 1] = item
+ table.insert(menu_list, item)
menu_func[#menu_list] = f
end
end
@@ -715,9 +715,9 @@ function cheatfind.startplugin()
end
local m
if optable[opsel] == "ltv" or optable[opsel] == "gtv" or optable[opsel] == "eqv" or optable[opsel] == "nev" then
- m = { _("Value"), value, "" }
+ m = { _("Value"), tostring(value), "" }
else
- m = { _("Difference"), value, "" }
+ m = { _("Difference"), tostring(value), "" }
end
local max = 100 -- max value?
menu_lim(value, 0, max, m)
@@ -792,7 +792,7 @@ function cheatfind.startplugin()
end
menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function()
- local m = { _("Match block"), matchsel, "" }
+ local m = { _("Match block"), tostring(matchsel), "" }
menu_lim(matchsel, 0, #matches[#matches], m)
if matchsel == 0 then
m[2] = _("All")
@@ -1017,7 +1017,7 @@ function cheatfind.startplugin()
end
if matches[#matches].count > 100 then
menu[#menu + 1] = function()
- local m = { _("Page"), matchpg, "on" }
+ local m = { _("Page"), tostring(matchpg), "on" }
local max
if matchsel == 0 then
max = math.ceil(matches[#matches].count / 100) - 1
diff --git a/plugins/inputmacro/inputmacro_menu.lua b/plugins/inputmacro/inputmacro_menu.lua
index 33223e9f20f..0c22de4a8f6 100644
--- a/plugins/inputmacro/inputmacro_menu.lua
+++ b/plugins/inputmacro/inputmacro_menu.lua
@@ -347,7 +347,7 @@ local function add_edit_items(items)
local input = manager.machine.input
local arrows
- items[#items + 1] = { _p('plugin-inputmacro', 'Name'), edit_name_buffer and (edit_name_buffer .. '_') or edit_current_macro.name, '' }
+ table.insert(items, { _p('plugin-inputmacro', 'Name'), edit_name_buffer and (edit_name_buffer .. '_') or edit_current_macro.name, '' })
edit_items[#items] = { action = 'name' }
if not (edit_start_selection or edit_start_step or edit_menu_active) then
edit_start_selection = #items
@@ -356,11 +356,11 @@ local function add_edit_items(items)
local binding = edit_current_macro.binding
local activation = binding and input:seq_name(binding) or _p('plugin-inputmacro', '[not set]')
- items[#items + 1] = { _p('plugin-inputmacro', 'Activation sequence'), activation, edit_switch_poller and 'lr' or '' }
+ table.insert(items, { _p('plugin-inputmacro', 'Activation sequence'), activation, edit_switch_poller and 'lr' or '' })
edit_items[#items] = { action = 'binding' }
local releaseaction = edit_current_macro.earlycancel and _p('plugin-inputmacro', 'Stop immediately') or _p('plugin-inputmacro', 'Complete macro')
- items[#items + 1] = { _p('plugin-inputmacro', 'On release'), releaseaction, edit_current_macro.earlycancel and 'r' or 'l' }
+ table.insert(items, { _p('plugin-inputmacro', 'On release'), releaseaction, edit_current_macro.earlycancel and 'r' or 'l' })
edit_items[#items] = { action = 'releaseaction' }
local holdaction
@@ -376,18 +376,18 @@ local function add_edit_items(items)
else
holdaction = string.format(_p('plugin-inputmacro', 'Prolong step %d'), #edit_current_macro.steps)
end
- items[#items + 1] = { _p('plugin-inputmacro', 'When held'), holdaction, arrows }
+ table.insert(items, { _p('plugin-inputmacro', 'When held'), holdaction, arrows })
edit_items[#items] = { action = 'holdaction' }
for i, step in ipairs(edit_current_macro.steps) do
- items[#items + 1] = { string.format(_p('plugin-inputmacro', 'Step %d'), i), '', 'heading' }
- items[#items + 1] = { _p('plugin-inputmacro', 'Delay (frames)'), step.delay, (step.delay > 0) and 'lr' or 'r' }
+ table.insert(items, { string.format(_p('plugin-inputmacro', 'Step %d'), i), '', 'heading' })
+ table.insert(items, { _p('plugin-inputmacro', 'Delay (frames)'), tostring(step.delay), (step.delay > 0) and 'lr' or 'r' })
edit_items[#items] = { action = 'delay', step = i }
if edit_start_step == i then
edit_start_selection = #items
end
- items[#items + 1] = { _p('plugin-inputmacro', 'Duration (frames)'), step.duration, (step.duration > 1) and 'lr' or 'r' }
+ table.insert(items, { _p('plugin-inputmacro', 'Duration (frames)'), tostring(step.duration), (step.duration > 1) and 'lr' or 'r' })
edit_items[#items] = { action = 'duration', step = i }
for j, input in ipairs(step.inputs) do
@@ -399,17 +399,17 @@ local function add_edit_items(items)
else
inputname = _p('plugin-inputmacro', '[not set]')
end
- items[#items + 1] = { string.format(_p('plugin-inputmacro', 'Input %d'), j), inputname, '' }
+ table.insert(items, { string.format(_p('plugin-inputmacro', 'Input %d'), j), inputname, '' })
edit_items[#items] = { action = 'input', step = i, input = j }
end
if step.inputs[#step.inputs].field then
- items[#items + 1] = { _p('plugin-inputmacro', 'Add input'), '', '' }
+ table.insert(items, { _p('plugin-inputmacro', 'Add input'), '', '' })
edit_items[#items] = { action = 'addinput', step = i }
end
if #edit_current_macro.steps > 1 then
- items[#items + 1] = { _p('plugin-inputmacro', 'Delete step'), '', '' }
+ table.insert(items, { _p('plugin-inputmacro', 'Delete step'), '', '' })
edit_items[#items] = { action = 'deletestep', step = i }
end
end
@@ -417,7 +417,7 @@ local function add_edit_items(items)
local laststep = edit_current_macro.steps[#edit_current_macro.steps]
if laststep.inputs[#laststep.inputs].field then
- items[#items + 1] = { '---', '', '' }
+ table.insert(items, { '---', '', '' })
arrows = 'lr'
if edit_insert_position > #edit_current_macro.steps then
@@ -425,7 +425,7 @@ local function add_edit_items(items)
elseif edit_insert_position < 2 then
arrows = 'r'
end
- items[#items + 1] = { _p('plugin-inputmacro', 'Add step at position'), edit_insert_position, arrows }
+ table.insert(items, { _p('plugin-inputmacro', 'Add step at position'), tostring(edit_insert_position), arrows })
edit_items[#items] = { action = 'addstep', step = i }
end
end
diff --git a/plugins/timer/init.lua b/plugins/timer/init.lua
index e7d7155b4c1..35dbb6431ac 100644
--- a/plugins/timer/init.lua
+++ b/plugins/timer/init.lua
@@ -38,7 +38,7 @@ function timer.startplugin()
{ '---', '', '' },
{ _p("plugin-timer", "Current time"), sectohms(time), "off" },
{ _p("plugin-timer", "Total time"), sectohms(total), "off" },
- { _p("plugin-timer", "Play Count"), play_count, "off" } },
+ { _p("plugin-timer", "Play Count"), tostring(play_count), "off" } },
highlight,
"idle"
end