aboutsummaryrefslogtreecommitdiffstats
path: root/make-feed.lua
diff options
context:
space:
mode:
authorgarret <garret@airmail.cc>2022-12-01 00:08:10 +0000
committergarret <garret@airmail.cc>2023-02-16 05:29:21 +0000
commit7b74dca5ecb1455ff525bce3b221a81da56a80dc (patch)
tree30da6e5979030472c358b88b2fde1e368b1b99c9 /make-feed.lua
parent89e494b46fbe120e012f4a13cfffc5f85cd9ad89 (diff)
downloaddepctrl-feedmaker-7b74dca5ecb1455ff525bce3b221a81da56a80dc.tar.gz
depctrl-feedmaker-7b74dca5ecb1455ff525bce3b221a81da56a80dc.tar.bz2
depctrl-feedmaker-7b74dca5ecb1455ff525bce3b221a81da56a80dc.zip
run scripts in a """"sandbox""""
don't have to fuck around with global variables any more, poggers
Diffstat (limited to 'make-feed.lua')
-rwxr-xr-xmake-feed.lua37
1 files changed, 22 insertions, 15 deletions
diff --git a/make-feed.lua b/make-feed.lua
index a0bcc89..0e34fdd 100755
--- a/make-feed.lua
+++ b/make-feed.lua
@@ -153,31 +153,38 @@ local function fake_depctrl(i)
}
end
-local function run_file(file, extension)
- local runner
- local old_require = require
- _G.require = function(obj)
- if obj == "l0.DependencyControl" then
- return fake_depctrl
+local function sandbox_require(obj)
+ if obj == "l0.DependencyControl" then
+ return fake_depctrl
+ else
+ local got, lib = pcall(require, obj)
+ if got then
+ return lib
else
- local got, lib = pcall(old_require, obj)
- if got then
- return lib
- else
- err(file .. " tried to require " .. obj .. " but couldn't. skipping and hoping it won't matter.")
- return {} --Some default value, hopefully it should be fine with it
- end
+ err("tried to require " .. obj .. " but couldn't. skipping and hoping it won't matter.")
+ return {} --Some default value, hopefully it should be fine with it
end
end
+end
+
+local function run_file(file, extension)
+ local runner
+ local env = deepcopy(_G) -- i dont care
+ env.require = sandbox_require
+ -- TODO: care
if extension == "moon" then
runner = moonscript.loadfile(file)
else
runner = loadfile(file)
end
+ if runner == nil then err(file .. " didn't load!") return nil end
+
+ setfenv(runner, env)
+
local worked, out = pcall(runner)
- if not worked then err("error when loading "..file..": ".. out) end
- _G.require = old_require
+ if not worked then err("error when executing "..file..": ".. out) return nil end
+ return env
end
local function get_macro_metadata(file)