2020-06-10 00:16:51 +00:00
|
|
|
local Util = require('opus.util')
|
|
|
|
|
|
|
|
-- some programs expect to be run in the global scope
|
|
|
|
-- ie. busted, moonscript
|
|
|
|
|
|
|
|
-- create a new sandbox mimicing pure lua
|
|
|
|
|
|
|
|
local fs = _G.fs
|
|
|
|
local shell = _ENV.shell
|
|
|
|
|
|
|
|
local env = Util.shallowCopy(_G)
|
|
|
|
Util.merge(env, _ENV)
|
|
|
|
env._G = env
|
|
|
|
|
|
|
|
env.arg = { ... }
|
2020-06-11 01:46:34 +00:00
|
|
|
env.arg[0] = shell.resolveProgram(table.remove(env.arg, 1) or error('file name is required'))
|
2020-06-10 00:16:51 +00:00
|
|
|
|
|
|
|
_G.requireInjector(env, fs.getDir(env.arg[0]))
|
|
|
|
|
|
|
|
local s, m = Util.run(env, env.arg[0], table.unpack(env.arg))
|
|
|
|
|
|
|
|
if not s then
|
2020-06-11 01:46:34 +00:00
|
|
|
error(m, -1)
|
2020-06-10 00:16:51 +00:00
|
|
|
end
|