Skip to content

Instantly share code, notes, and snippets.

@ar1a
Last active November 22, 2015 09:49
Show Gist options
  • Save ar1a/d8980c896caa75ab8c18 to your computer and use it in GitHub Desktop.
Save ar1a/d8980c896caa75ab8c18 to your computer and use it in GitHub Desktop.
lua console v1.2 by aria
--[[MUST BE RUN ON LUA 5.3 OR DEBUG HOOKS WONT WORK]]
os.execute("cls")
print([[ __ ________ _ _____ ____ __ __ ______ _____ _____
\ \ / / ____| | / ____/ __ \| \/ | ____| /\ | __ \|_ _| /\
\ \ /\ / /| |__ | | | | | | | | \ / | |__ / \ | |__) | | | / \
\ \/ \/ / | __| | | | | | | | | |\/| | __| / /\ \ | _ / | | / /\ \
\ /\ / | |____| |___| |___| |__| | | | | |____ / ____ \| | \ \ _| |_ / ____ \
\/ \/ |______|______\_____\____/|_| |_|______| /_/ \_\_| \_\_____/_/ \_\]])
print([[ _ _____ _ __ ___
| | / ____| | | /_ | |__ \
| |_ ___ | | ___ _ __ ___ ___ | | ___ __ _| | ) |
| __/ _ \ | | / _ \| '_ \/ __|/ _ \| |/ _ \ \ \ / / | / /
| || (_) | | |___| (_) | | | \__ \ (_) | | __/ \ V /| |_ / /_
\__\___/ \_____\___/|_| |_|___/\___/|_|\___| \_/ |_(_)____|
]])
print('Type help for commands.\nType exit to quit.\nLua code is accepted.')
local env = {}
function istable(t) return type(t) == 'table' end
function table.Copy( t, lookup_table )
if ( t == nil ) then return nil end
local copy = {}
setmetatable( copy, debug.getmetatable( t ) )
for i, v in pairs( t ) do
if ( not istable( v ) ) then
copy[ i ] = v
else
lookup_table = lookup_table or {}
lookup_table[ t ] = copy
if ( lookup_table[ v ] ) then
copy[ i ] = lookup_table[ v ] -- we already copied this table. reuse the copy.
else
copy[ i ] = table.Copy( v, lookup_table ) -- not yet copied. copy it.
end
end
end
return copy
end
env = table.Copy(_G)
commands = {}
commands.help = function()
print('---------HELP DIALOG---------')
for command, executor in pairs(commands) do
print(command)
end
print('-----------------------------')
end
commands.cmd = function()
os.execute("start")
end
commands.exit = function()
os.exit(0)
end
commands.x = commands.exit
commands.restart = function()
env = table.Copy(_G) --restores the lua environment
commands.clear()
end
commands.clear = function()
os.execute("cls")
print([[ _____ _ __ ___
/ ____| | | /_ | |__ \
| | ___ _ __ ___ ___ | | ___ __ _| | ) |
| | / _ \| '_ \/ __|/ _ \| |/ _ \ \ \ / / | / /
| |___| (_) | | | \__ \ (_) | | __/ \ V /| |_ / /_
\_____\___/|_| |_|___/\___/|_|\___| \_/ |_(_)____|
]])
print('Type help for commands.\nType exit to quit.\nLua code is accepted.')
end
commands.cls = commands.clear
commands.exec = function(input)
if(input == "") then
print("ERROR: No args!")
return
end
local func, err = load("return " .. input,nil,'t', env)
if func == nil then
local func1, err1 = load(input, nil, 't', env)
--setfenv(func1,env)
if(func1 == nil) then
print(err1)
else
local start = os.clock()
local thread = coroutine.create(func1)
debug.sethook( thread, function()
if os.clock() > start + 2.0 then
print("maximum execution time exceeded")
error( "maximum execution time exceeded", 2 )
end
end, "", 128)
pcall(coroutine.resume,thread)
end
else
--setfenv(func,env)
print( select( 2, pcall( func ) ) )
end
end
local currentcommand
while true do
currentcommand = io.read()
if currentcommand == "" then goto continue end
local cmd, args = currentcommand:match("^([^%s]+) ?(.*)$")
if cmd == nil then
print("ERROR: no comamnd")
end
local command = commands[cmd]
if command ~= nil then
command(args)
else
commands["exec"](currentcommand)
end
::continue::
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment