lua program can now be quit using 'exit()' function

This commit is contained in:
Florian Nücke 2013-10-20 18:34:32 +02:00
parent b52cc44598
commit 60118f19cc

View File

@ -1,13 +1,15 @@
while term.isAvailable() do
print("Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio")
local running = true
local env = setmetatable({exit=function() running = false end}, {__index=_ENV})
while running and term.isAvailable() do
io.write("lua> ")
local command = io.read()
if not command then
return -- eof
end
local code, result = load("return " .. command, "=stdin")
local code, result = load("return " .. command, "=stdin", env)
if not code then
code, result = load(command, "=stdin") -- maybe it's a statement
code, result = load(command, "=stdin", env) -- maybe it's a statement
end
if code then
local result = table.pack(pcall(code))