summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2016-04-11 17:39:35 -0500
committer cracyc <cracyc@users.noreply.github.com>2016-04-11 17:39:35 -0500
commitb09ae03b65762ebdef7b1c274b857082f20665fd (patch)
treeeb7e1bf3d832076282fd05121bf56252a6a49db4 /plugins
parentb5486236918e8565b27e79a99d7c3112f6cff00e (diff)
plugins/cheat: add safe table functions to sandbox (nw)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/cheat/init.lua40
1 files changed, 15 insertions, 25 deletions
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua
index 2dee3677f34..ecaf6237377 100644
--- a/plugins/cheat/init.lua
+++ b/plugins/cheat/init.lua
@@ -22,9 +22,9 @@
-- ...
-- },
-- "screen": {
--- "varname": "tag"
--- },
+-- "varname": "tag",
-- ...
+-- },
-- "region": {
-- "varname": "tag",
-- ...
@@ -153,16 +153,18 @@ function cheat.startplugin()
tobcd = tobcd,
frombcd = frombcd,
pairs = pairs,
- ipairs = ipairs }
+ ipairs = ipairs,
+ table_insert = table.insert,
+ table_remove = table.remove }
cheat.enabled = false
-- verify scripts are valid first
if not cheat.script then
return
end
for name, script in pairs(cheat.script) do
- script = load(script, cheat.desc .. name, "t", cheat.cheat_env)
+ script, err = load(script, cheat.desc .. name, "t", cheat.cheat_env)
if not script then
- print("error loading cheat script: " .. cheat.desc)
+ print("error loading cheat script: " .. cheat.desc .. " " .. err)
cheat = { desc = cheat.desc .. " error" }
return
end
@@ -233,21 +235,9 @@ function cheat.startplugin()
if not param then
return
end
- if not param.min then
- param.min = 0
- else
- param.min = tonumber(param.min)
- end
- if not param.max then
- param.max = #param.item
- else
- param.max = tonumber(param.max)
- end
- if not param.step then
- param.step = 1
- else
- param.step = tonumber(param.step)
- end
+ param.min = tonumber(param.min) or 0
+ param.min = tonumber(param.min) or #param.item
+ param.step = tonumber(param.step) or 1
if param.item then
for count, item in pairs(param.item) do
if not item.value then
@@ -432,13 +422,13 @@ function cheat.startplugin()
emu.register_start(function()
cheats = load_cheats()
- for num, cheat in ipairs(cheats) do
+ for num, cheat in pairs(cheats) do
parse_cheat(cheat)
end
end)
emu.register_frame(function()
- for num, cheat in ipairs(cheats) do
+ for num, cheat in pairs(cheats) do
if cheat.enabled and cheat.script.run then
cheat.script.run()
end
@@ -447,7 +437,7 @@ function cheat.startplugin()
emu.register_frame_done(function()
line = 0
- for num, draw in ipairs(output) do
+ for num, draw in pairs(output) do
if draw.type == "text" then
if not draw.color then
draw.scr:draw_text(draw.x, draw.y, draw.str)
@@ -455,9 +445,9 @@ function cheat.startplugin()
draw.scr:draw_text(draw.x, draw.y, draw.str, draw.color)
end
elseif draw.type == "line" then
- draw.scr:draw_line(draw.x1, draw.x2, draw.y1, draw.y2, draw.color)
+ draw.scr:draw_line(draw.x1, draw.y1, draw.x2, draw.y2, draw.color)
elseif draw.type == "box" then
- draw.scr:draw_box(draw.x1, draw.x2, draw.y1, draw.y2, draw.bgcolor, draw.linecolor)
+ draw.scr:draw_box(draw.x1, draw.y1, draw.x2, draw.y2, draw.bgcolor, draw.linecolor)
end
end
output = {}