run lua commands from shell and other tweaks

This commit is contained in:
kepler155c@gmail.com
2020-07-25 18:52:13 -06:00
parent cb1126e216
commit d6f61acace
5 changed files with 61 additions and 21 deletions

View File

@@ -6,3 +6,49 @@ end
_ENV.shell.setCompletionFunction("packages/common/edit.lua", c)
_ENV.shell.setCompletionFunction("packages/common/hexedit.lua", c)
_ENV.shell.registerHandler(function(env, command, args)
if command:match('^!') then
return {
title = 'lua',
path = table.concat({ command:match('^!(.+)'), table.unpack(args) }, ' '),
args = args,
load = function(s)
return function()
local fn, m
local wrapped
fn = load('return (' ..s.. ')', 'lua', nil, env)
if fn then
fn = load('return {' ..s.. '}', 'lua', nil, env)
wrapped = true
end
if fn then
fn, m = pcall(fn)
if #m <= 1 and wrapped then
m = m[1]
end
else
fn, m = load(s, 'lua', nil, env)
if fn then
fn, m = pcall(fn)
end
end
if fn then
if m or wrapped then
require('opus.util').print(m or 'nil')
else
print()
end
else
_G.printError(m)
end
end
end,
env = env,
}
end
end)