mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-12 08:50:04 -04:00
lua program can now be quit using 'exit()' function
This commit is contained in:
parent
b52cc44598
commit
60118f19cc
@ -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> ")
|
io.write("lua> ")
|
||||||
local command = io.read()
|
local command = io.read()
|
||||||
if not command then
|
if not command then
|
||||||
return -- eof
|
return -- eof
|
||||||
end
|
end
|
||||||
|
local code, result = load("return " .. command, "=stdin", env)
|
||||||
local code, result = load("return " .. command, "=stdin")
|
|
||||||
if not code then
|
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
|
end
|
||||||
if code then
|
if code then
|
||||||
local result = table.pack(pcall(code))
|
local result = table.pack(pcall(code))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user