-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.lua
More file actions
30 lines (29 loc) · 906 Bytes
/
Copy pathshell.lua
File metadata and controls
30 lines (29 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- Quick and dirty lua shell in lua.
-- This may prove useful in testing/debugging.
function lua_shell(greet)
local command, next_line, chunk, error
io.write((greet and greet..'/' or ''),'Lua shell:\n')
repeat
io.write('Lua> ')
next_line, command = io.read '*l', ''
if next_line then
next_line, print_it = next_line:gsub('^=(.*)$', 'return %1')
repeat
command = command..next_line..'\n'
chunk, error = loadstring(command, '')
if chunk then
(function (success, ...)
if not success then error = ...
elseif print_it ~= 0 then print(...)
end end)(pcall(chunk))
break
end
if not error:find('<eof>') then break end
io.write('>> ')
next_line = io.read '*l'
until not next_line
if error then print((error:gsub('^[^:]*:(.*)$', 'stdin:%1'))) end
end
until not next_line
io.write 'Goodbye\n'
end