Skip to content

Instantly share code, notes, and snippets.

@AndrewTsao
Created March 24, 2013 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewTsao/5230653 to your computer and use it in GitHub Desktop.
Save AndrewTsao/5230653 to your computer and use it in GitHub Desktop.
repl.lua
function repl()
local cmd, res, msg1, msg2
-- R
io.write '>'
cmd = io.read()
if not cmd or #cmd == 0 then
return repl()
end
res, msg1 = loadstring(cmd, 'repl')
if not res then
res, msg2 = loadstring('return (' .. cmd .. ')', 'repl')
end
while not res do
io.write ' >'
local part = io.read()
if not part then
io.write(msg1)
io.write '\n'
return repl()
end
cmd = cmd .. '\n' .. part
res, msg1 = loadstring(cmd, 'repl')
if not res then
res, msg2 = loadstring('return (' .. cmd .. ')', 'repl')
end
end
-- E
local ret = pack(pcall(res))
-- P
if ret.n == 1 then
return repl()
end
for i = 2, ret.n do
io.write(tostring(ret[i]))
if i < ret.n then io.write('\t') end
end
io.write('\n')
return repl()
end
repl()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment